Sign in to follow this  
Drew_Benton

Unity [.net] First C# Program - GameDev Thread Saver

Recommended Posts

I've recently started taking a look at C# since it's been on my todo list for so long. And what better way to start learning it with other than making tools! This C# program is called Thread Saver and what it does is you give it an id of the GameDev.net thread you want to save, and it will save the entire thread, all pages, into one html file to your hard drive. Now you will have to look at the code to see everything I did. It is very brekable right now, but anything that does popup with specific threads could be fixed with more code. One of the major things that I added in was the resolving of all relative links to absolute links, so when you save the page, it looks like a gamedev page rather than what you get when you save it from your browser. Here's the complete source, since I have no reason to keep it closed. There are lots of room for improvements and modifications. If you uncomment out a lot of the stuff in the CombineGameDevThread function, then you will end up with a nice page that is print ready! Since there are a lot of slashes and tags the forum might eat, I will just post the file instead. Now for my C# questions/comments from making this: 1. Is the StreamReader.ReadToEnd(); function used in a good sense how I did it? Is there anything that would be faster? I tried using the StreamReader.Read function, but I could not figure out how to convert from a char[] to a string. 2. How do you convert from a char[] to a string? The .toString method returns simply System.char[] or whatever that string is for the object name. 3. Why, oh why do functions such as Replace, Insert, etc.. return the new string rather than modify the current! It took me so long to figure out that the new modified string is returned rather than the updated itself. I can see the logics, but darn, that was so confusing! 4. It took me a bit to figure out that .Find is really .IndexOf [headshake] 5. Other than that, does anyone see any improvements that I can make in terms of C# concepts? Ok thanks for any help/suggestions. As for the program, if you want to do some comparing, I saved the thread, Single Word Game, and my results were:
102 Pages
...
Operation time: 358.234 seconds
The final file is 7.962MB and takes quite a bit for FF to load [lol]. I plan to improve this a lot more, but for right now, I'm just learning the concepts. If there's anything you'd like to see in it, feel free to make a suggestion and I will write it down. - Drew

Share this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
Now for my C# questions/comments from making this:

1. Is the StreamReader.ReadToEnd(); function used in a good sense how I did it? Is there anything that would be faster? I tried using the StreamReader.Read function, but I could not figure out how to convert from a char[] to a string.

2. How do you convert from a char[] to a string? The .toString method returns simply System.char[] or whatever that string is for the object name.

3. Why, oh why do functions such as Replace, Insert, etc.. return the new string rather than modify the current! It took me so long to figure out that the new modified string is returned rather than the updated itself. I can see the logics, but darn, that was so confusing!


I'm tired and about to crash, but here is a little help. Strings are immutable objects, meaning that they can't be changed once they are set. Since that is the case,, and function that returns a different string must make a new string. If you are modifying a string a lot, consider using its mutable cousin the StringBuilder. As far as converting char[] to a string, just pass the character array into the string constructor.

Share this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
Now for my C# questions/comments from making this:

1. Is the StreamReader.ReadToEnd(); function used in a good sense how I did it? Is there anything that would be faster? I tried using the StreamReader.Read function, but I could not figure out how to convert from a char[] to a string.

Dunno, would have to read the code to know. [grin]
Quote:

2. How do you convert from a char[] to a string? The .toString method returns simply System.char[] or whatever that string is for the object name.

String constructor
Quote:

3. Why, oh why do functions such as Replace, Insert, etc.. return the new string rather than modify the current! It took me so long to figure out that the new modified string is returned rather than the updated itself. I can see the logics, but darn, that was so confusing!

strings are immutable, aka: they cannot change. Use StringBuilder/StringWriter/StringReader.
Quote:

4. It took me a bit to figure out that .Find is really .IndexOf [headshake]

lol, made sense to me.
Quote:

5. Other than that, does anyone see any improvements that I can make in terms of C# concepts?

Your naming scheme is inconsistant. Stop mixing cases of the method names. If you are going to use upper camel case, then stick with that, mixing lower and upper camel case (pascal case) just confuses things.

It's also not done in a very OO fashion. You might also want to look into the MS HTML processing stuff. You can use it to build a DOM of the pages, find hyperlinks, images, stylesheets. That information could be used to download a whole tree of the pages, based on the information. You are replicating a lot of code that's already been done.

Definantly need to use a StringBuilder, your current code is very....memory inneficient.

Share this post


Link to post
Share on other sites
If you're interested in efficiency, you might want to check out the CLR Profiler. An article on it is available here. The call graph view is interesting. It'll let you see what functions are taking up the most time.

Regarding your code itself, like Washu I'd recommend naming consistency. I'd also recommend following .NET naming conventions for even more consistency; I've always found it annoying when Java naming conventions sneak into .NET and vice versa. The link is quite in depth; you can find summaries through Google.

Share this post


Link to post
Share on other sites
Sorry guys for the late replies, I will be getting back to this thread in a week or so when I have my dev computer up again. It's broken now so I am working with an old celeron 633mhz. It's not that bad and Visual C# 2005 Beta > Visual Studio 2003 C# [wink]. I'll start reading all the replies and respond again soon. Thanks for all your time!

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  

  • Announcements

  • Forum Statistics

    • Total Topics
      628388
    • Total Posts
      2982403
  • Similar Content

    • By sveta_itseez3D
      itSeez3D, a leading developer of mobile 3d scanning software, announced today a new SDK for its automatic 3D avatar generation technology, Avatar SDK for Unity. The Avatar SDK for Unity is a robust plug-n-play toolset which enables developers and creatives to integrate realistic user-generated 3D avatars into their Unity-based applications. SDK users can allow players to create their own avatars in the application or integrate the SDK into their own production processes for character design and animation.
      “Virtual avatars have recently become increasingly popular, especially in sports games and social VR apps. With the advance of VR and AR, the demand to get humans into the digital world is only increasing”, said Victor Erukhimov, itSeez3D CEO. “Our new Avatar SDK for Unity makes it super-easy to bring the avatar technology into any Unity-based game or VR/AR experience. With the Avatar SDK for Unity now every developer can bring face scanning technology into their games and allow players to create their own personalized in-game avatars, making the gameplay much more exciting and immersive.”
      Key features of the Avatar SDK for Unity:
      Automatic generation of a color 3D face model from a single selfie photo in 5-10 seconds (!). Works best with selfies, but can be used with any portrait photo.
      Shape and texture of the head model are unique for each person, synthesized with a deep learning algorithm crafted by computer vision experts
      Head models support runtime blendshape facial animations (45 different expressions)
      Generated 3D heads include eyes, mouth, and teeth
      Algorithms synthesize 3D meshes in mid-poly resolution, ~12k vertices, and ~24k triangles
      Six predefined hairstyles with hair-recoloring feature (many more available on request)
      Avatar generation API can be used in design-time and in run-time, which means you can allow users to create their own avatars in your game
      Cloud version is cross-platform, and offline version currently works on PCs with 64-bit Windows (support for more platforms is coming soon)
      Well-documented samples showcasing the functionality.
       
      Availability
      The Avatar SDK for Unity is offered in two modes - “Cloud” and “Offline”. The “Cloud” version is available at http://avatarsdk.com/ and the “Offline” version is available by request at support@itseez3d.com.
      ###
      About itSeez3D
      At itSeez3D, we are working on the computer vision technology that turns mobile devices into powerful 3D scanners. itSeez3D has developed the world's first mobile 3D scanning application that allows to create high-resolution photorealistic 3D models of people's' faces, bodies and objects. The application is available for iOS and Windows OS mobile devices powered with 3D cameras. In 2016 the company introduced Avatar SDK that creates a realistic 3D model of a face from a single selfie photo. To learn more about itSeez3D scanning software and 3D avatar creation technology, please visit www.itseez3d.com and www.avatarsdk.com.

      View full story
    • By sveta_itseez3D
      itSeez3D, a leading developer of mobile 3d scanning software, announced today a new SDK for its automatic 3D avatar generation technology, Avatar SDK for Unity. The Avatar SDK for Unity is a robust plug-n-play toolset which enables developers and creatives to integrate realistic user-generated 3D avatars into their Unity-based applications. SDK users can allow players to create their own avatars in the application or integrate the SDK into their own production processes for character design and animation.
      “Virtual avatars have recently become increasingly popular, especially in sports games and social VR apps. With the advance of VR and AR, the demand to get humans into the digital world is only increasing”, said Victor Erukhimov, itSeez3D CEO. “Our new Avatar SDK for Unity makes it super-easy to bring the avatar technology into any Unity-based game or VR/AR experience. With the Avatar SDK for Unity now every developer can bring face scanning technology into their games and allow players to create their own personalized in-game avatars, making the gameplay much more exciting and immersive.”
      Key features of the Avatar SDK for Unity:
      Automatic generation of a color 3D face model from a single selfie photo in 5-10 seconds (!). Works best with selfies, but can be used with any portrait photo.
      Shape and texture of the head model are unique for each person, synthesized with a deep learning algorithm crafted by computer vision experts
      Head models support runtime blendshape facial animations (45 different expressions)
      Generated 3D heads include eyes, mouth, and teeth
      Algorithms synthesize 3D meshes in mid-poly resolution, ~12k vertices, and ~24k triangles
      Six predefined hairstyles with hair-recoloring feature (many more available on request)
      Avatar generation API can be used in design-time and in run-time, which means you can allow users to create their own avatars in your game
      Cloud version is cross-platform, and offline version currently works on PCs with 64-bit Windows (support for more platforms is coming soon)
      Well-documented samples showcasing the functionality.
       
      Availability
      The Avatar SDK for Unity is offered in two modes - “Cloud” and “Offline”. The “Cloud” version is available at http://avatarsdk.com/ and the “Offline” version is available by request at support@itseez3d.com.
      ###
      About itSeez3D
      At itSeez3D, we are working on the computer vision technology that turns mobile devices into powerful 3D scanners. itSeez3D has developed the world's first mobile 3D scanning application that allows to create high-resolution photorealistic 3D models of people's' faces, bodies and objects. The application is available for iOS and Windows OS mobile devices powered with 3D cameras. In 2016 the company introduced Avatar SDK that creates a realistic 3D model of a face from a single selfie photo. To learn more about itSeez3D scanning software and 3D avatar creation technology, please visit www.itseez3d.com and www.avatarsdk.com.
    • By Canislupus54
      I'm looking for programmers for an rpg I want to make. If you're wondering what "semi-turn based" means, it means that you take turns, but instead of a rigid back and forth like Pokemon, a timer determines when you can act, a sort of modernization of the classic Final Fantasy Active Time Battle system. Right now, I'm looking for programmers to create a prototype of both the combat system and the movement outside of combat. Preferably for Unity C#. Concept artists, particularly for characters, and writers to help me flesh out the character and story aspects, would also be helpful.
      Here's a concept doc to fully explain things: https://docs.google.com/document/d/1ObDMAUWsndSAJ1EpQGRDxtR8Xl9xPotx89OZ0sgRaIw/edit?usp=sharing
      If you can fill another role and are interested, feel free to let me know as well.
      At the moment, this is purely a hobby project, with no payment planned. If we produce something we feel we can release, then of course we'll work out something for compensation. But, again, don't join this project counting on payment.
      If you're interested, contact me on here, or at jordestoj@yahoo.com . Thanks.
  • Popular Now