Jump to content
  • Advertisement
Sign in to follow this  
AxeGuywithanAxe

Unity Learning from Other's Code

This topic is 790 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, this is just a general question about the practices of learning coding. How exactly do you guys learn from other's code without it completely overriding your own ability to solve a similar solution. I ask this because I am currently working on my own game engine. After using Unity/Source/CryEngine/Unreal Engine 4, I have learned a lot about efficient rendering pipelines, shader abstractions, and multithreading. I see this directly affecting my own code writing to the point that it feels like copying to me. For Example, Unreal Engine uses the "FVertexFactory" class to handle runtime shader selection ; vertex stream management , and shader parameter binding. It also uses "FVertexFactoryType" as a way to abstract shader input, each FVertexFactoryType has a corresponding shader file that determines how to get common information like tangents/normals/position etc. Because of this, I have added a similar class to my engine that handles the same logic but with a few extensions, such as dynamic instancing. Source Engine and UE4 both have a class for each shader that they use in engine, and I have chosen to use something similar to their implementation. The engine for The Order 1886 uses a text description language for material shader generation , and I have implemented a similar solution. It seems that it might get to a point where my entire code base is just a combination of different engines that i've used, or read about, instead of something that is purely of my design. I wanted to know if this is something that other's have experienced, both novices and industry professionals, and is it okay? In a gdc article for Uncharted 2's Shader system, they showed a code base that looked eerily similar to UE3's, even stating that their developers had a background in Unreal, So Should I somehow try to forget , or steer away from, the implementations that the best game engines use? 

Edited by AThompson

Share this post


Link to post
Share on other sites
Advertisement

I'm writing an engine to learn some of the internal mechanics, such as rendering ; entity-component systems , file management/streaming, object reflection,  physics, and etc. I built a few small engines previously for courses, like a bowling game. Now I want to build one as an entry into my portfolio . My end result is to create a small turn based rpg

Share this post


Link to post
Share on other sites

In response to the earlier section of your response, thank you for it by the way, my issue seems to not be that I don't understand why they took the approaches that they did, but that I can not find a better way to achieve the same result, which causes my code to mirror theirs in a way . For example when it comes to shader abstraction , creating a class per shader reduces the cost of wasting time on parameter look ups. It also helps with shader type look ups and serialization , using somewhat of a class factory. Abstracting the vertex input of your shaders , via FVertexFactory in UE4 , allows you to keep the same main shader code, and just change the small shader sections, such as getting local position of the vertex, which is mandatory for a good shader generator. Having a c++ class , and a class factory via FVertexFactoryType, forces a contract between c++ client code and shader code. 

Share this post


Link to post
Share on other sites

Thank you Glass_Knife , I've actually gone through a fair amount of those code bases. My question was more related to; what is the thin line between learning from another code base to better yours, and what is just copying the work done by other engineers, which can be really bad, especially if it's open source but still copywrited.

Share this post


Link to post
Share on other sites

If you're reading other people's code, you will see stuff done in a way you've never seen it before.  Maybe it's a new algorithm, or C++ trick, or just understand how they structure their header files and code, resources, and build scripts.

 

If you are just copying other's code, you aren't learning anything.

Share this post


Link to post
Share on other sites

Well I'm not explicitly copying, it's more like I'm reading through some of these great game engines, and seeing that the more I read, the more my code looks closer to these engines. So in reality the code isn't 100% of my own creation, but my modified version of what I learned from a reading. Maybe I'm just overthinking it.

Share this post


Link to post
Share on other sites

I'm writing an engine to learn some of the internal mechanics, such as rendering ; entity-component systems , file management/streaming, object reflection,  physics, and etc. I built a few small engines previously for courses, like a bowling game. Now I want to build one as an entry into my portfolio . My end result is to create a small turn based rpg

 

 

Looking at existing art is a good way to understand where the field of interest is, today. Re-creating that is a good way to understand what's happening inside.

 

However, (and this may also be where you're struggling with), at the end of the day, you've reached what already exists. At this point you can dump your engine in the trash (it has done its job to help you understanding the current solutions). It's better to use anything existing, if only for the sole purpose that it is actively being maintained by someone else than you.

 

 

I am a software engineer, never take job interviews, and I am totally not into game engines, but if I would do both things, and get you, my question would be something like "You made your own engine, interesting. Please tell me how it differs from the existing ones, and why?"

 

[Scared you there, eh?]

 

 

To understand the question, take a step back.

 

In engineering, there are always trade-offs. You want the best of everything, but you cannot have it, so you let go of some area in order to gain in a different area that you consider more important. By making such design decisions you arrive at some solution, which is thus the least bad in all design goals.

 

It's the same in code. The design space of "an game engine" is close to infinite. To arrive at a solution, you must make choices. With each choice you narrow the design space by chopping off some area that you consider less interesting. As engine designer making the choice, however, you better have a deep understanding of what you throw away.

 

Existing art is just unique solutions in an infinite design space (like small dots in the empty universe). They have made a zillion trade-offs in the design space to arrive at where-ever they are in the design space. As engine designer, you should understand what the current art dropped, and why that is reasonable. If your solution is different, you must have made a different trade-off somewhere, and be different/better in some area.

Edited by Alberth

Share this post


Link to post
Share on other sites

Learn from more than one. Chances are they won't solve anything the same way, which means now you've got two great ideas to copy, and you can't copy both :P

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!