Sign in to follow this  

Unity How do game engines compile?

This topic is 2481 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

Hello,

I've been trying to deal with this problem for a while now, I'm currently working on a game engine I could use to help myself later on, the thing is made in .NET C++, and is similiar in design plan to RPG Maker, and GameMaker and the such in the way that it handles the creation and handling of maps and events in the UI from .NET.

After the project is done, it is exported to code files in the format of native C++ using SDL.

Now, my problem is this part, I have the code generator mostly ready, it creates all the neccassery files for compilement and works well, now my problem is with actually compiling it automatically from within the GUI in .NET, I was thinking of using the CMD and vcvarsall.bat, but that didn't work, and thought about using makefiles, but that doesn't work on Windows, and I don't want the program to depend on too much external software by using NMake or something.

So, I guess, what I've come here to ask would be what are common methods for this type of thing? How do the popular engines, like the aformentioned ones, or Unity, or UDK, or any of the handful out there, work? How do they compile the work on them into and executable?

Share this post


Link to post
Share on other sites
Unity has an embedded Mono runtime, which JIT-compiles .NET bytecode. The UDK uses UnrealScript, which is compiled to bytecode, and interpreted by Unreal's virtual machine. I'm not really understanding what exactly you have made. A code generator? Please elaborate.

Share this post


Link to post
Share on other sites
Yes, it's a code generator, it takes all the data you input to it when you make the maps, events, and various other data and puts it in C++ format code through the algorithms of the program, is there any way to compile such a thing at run time?

And could I ask for some more information about those 2 methods you mentioned? Are they plausible for hobbyist use? How do you use them? Where can I read more, tutorials peraphs?

Thanks for replying.

Share this post


Link to post
Share on other sites
You can't compile C++ at runtime.

That being said, I have seen the Tiny C Compiler (found [url="http://bellard.org/tcc/"]here[/url]) used to compile C code at runtime and execute it. It's reasonably fast, but still not a popular solution when programming games. I'm still not quite understanding this code generator you have made. Did you write it yourself, or are you referring to the "designer view" in Visual Studio .NET (or something similar)?

Both [url="http://www.unity3d.com"]Unity[/url] and the [url="http://udk.com/"]UDK[/url] are free to use. You will not be able to take whatever C++ code you're generating and run it in either of these engines. Unity is programmed using C#, JavaScript, or Boo. The UDK is programmed using UnrealScript and Kismet. I would advise you to check these engines out and learn how to use them before you try to write your own engine (if you write an engine at all - you should be writing games instead). Both of these engines have large communities and great resources to help you learn. They are both suitable for commercial and small-scale projects.

Share this post


Link to post
Share on other sites
I'm writing the engine myself, it's using the .NET form project as a GUI, but implements algorithms for outputting .cpp and .h files for every map and event on the map, as well as graphics management and the such, I'm sorry if I haven't made that clear, and it has nothing to do with neigther UDK nor Unity, I was just giving examples as to what I mean in the way I want to compile.

As for TCC, it's nice, but I need a way to compile C++ code, not C, searching around about it suggest that it doesn't support that.

Share this post


Link to post
Share on other sites
You could compile the C++ as a DLL using Visual C++, GCC, or something similar, then link it at runtime. Just know that there are much better and more practical approaches to this. Consider a scripting language like Lua or Python. Or have your engine generate XML or JSON when storing level data - these are much easier to load up and use.

Share this post


Link to post
Share on other sites
Hi KazenoZ,

I'm not sure what you'd call an application which generates the c++ code for a game, but I don't think that "game engine" is entirely fitting - it's more like a "game generator" (although the common code this generated source code relies upon might be called a game engine). I'm also not familiar with any similar products - AFAIK this isn't such a common approach to a game-creation tool.

That said, you have a few options:

[list][*]Write your own c++ compiler[*]Bundle an existing compiler with your product (ensuring licensing and such as all above-board)[*]Require the user to have a compiler already available[*]Scrap the c++ code generation/compilation model - you might generate code in a proprietary domain-specific language and write a VM. You could take an entirely data-driven approach (where a specific game consists entirely of "configuration"/content, and the same "host" application is always used to run the game - if you allow lots of complicated and varied options then this might become practically indistinguishable from creating a language/VM)[/list]

Share this post


Link to post
Share on other sites
Thanks alot for the comments guys, especially you, Virus, I've taken fancy to the 4th approach and already started work on it and it seems great so far, perfect for my cause, thanks much for the tip.

Share this post


Link to post
Share on other sites
[quote name='WavyVirus' timestamp='1298490388' post='4778096']
[list][*]Write your own c++ compiler[*]Bundle an existing compiler with your product (ensuring licensing and such as all above-board)[*]Require the user to have a compiler already available[*]Scrap the c++ code generation/compilation model - you might generate code in a proprietary domain-specific language and write a VM. You could take an entirely data-driven approach (where a specific game consists entirely of "configuration"/content, and the same "host" application is always used to run the game - if you allow lots of complicated and varied options then this might become practically indistinguishable from creating a language/VM)[/list][/quote]
[url="http://llvm.org/"]LLVM[/url] is a good option for both ahead of time compilation and JIT compiling as part of a VM and it is distributed under an [url="http://llvm.org/svn/llvm-project/llvm/trunk/LICENSE.TXT"]unrestrictive license[/url]. Clang is distributed under the GPL because the frontend uses GCC, but you may be able to bundle it anyway as long as you comply with the GPL (afaik since your code is separate from the GCC bianries you can release your code however you like, but you will want to check this yourself).

Of course, if you are embedding a full blown language (rather than data-driven configuration), unless you want something very specific to your engine, it would usually be better (easier and less buggy) to not write your own language and use an existing embeddable language like Lua (and LuaJIT if you want super fast), AngelScript, Squirrel or even Python. Actually, since you said you are using .NET you have a bunch of options there too. You could embed C# or F# or some other .NET language. Of course, then, as you said, you will need to bundle the compiler and will have to check the terms for the specific language. The engine wouldn't need to bundle these tools to the gamer, but the editor/tools would.

Share this post


Link to post
Share on other sites
Ok, I'm getting a little lost here, could you guys sharpen my terminology?

So, a game ENGINE, is actually not a program you build the game through, but rather a set of functions that are externally linked to your program to make it easier to still WRITE in a regular compiler?

What IS such a program called then? How would you define RPG Maker for example?

And exactly is a VM? A virtual machine, I think? What does it even mean?


I'm sorry, it's just the first time I'm dealing with such a project, I'm not quite keen on the terms...

Share this post


Link to post
Share on other sites
First off I should point out that I agree with dublindan that, if you are more interested in getting results than experimenting with programming languages, generating code in an existing scripting language is probably the most practical approach

[quote name='KazenoZ' timestamp='1298718694' post='4779274']Ok, I'm getting a little lost here, could you guys sharpen my terminology here?


So, a game ENGINE, is actually not a program you build the game through, but rather a set of functions that are externally linked to your program to make it easier to still WRITE in a regular compiler?

What IS such a program called then? How would you define RPG Maker for example?[/quote]


The definition of "game engine" isn't unanimously agreed upon, but the following is my attempt to define it:

[i]A game engine is a collection of software components used in the production of games, which is separate from the content, game-world and gameplay rules that define a particular game. It is reusable, sufficiently generic code which aids in the creation of many different games by exposing an interface to common, often lower-level functionality such as rendering, audio or physics systems.[/i]

The line between game and engine is often blurry - an engine could be extremely generic, or targeted at a more specific type of game (it might, for example, include the concept of a "ragdoll", a "weapon" or a "quest" - a more generic game engine might only deal with things as specific as a "sprite", "sound" or "mesh"). A game engine might come with a set of tools designed around it, or might be simply a collection of code.[i]
[/i]

I would call RPG Maker a "game development tool" or something similar. again, I don't know if there are black and white definitions here.




[quote]And exactly is a VM? A virtual machine, I think? What does it even mean?[/quote]


A "machine", in this context, can be thought of as a system for processing a sequence instructions encoded in some specific format. Your PC is a machine, with a CPU processing a list low-level instructions from a well-defined set of possible instructions (e.g. "read a byte from location X, storing it in Y", "add value X to the value in location Y"). A "virtual machine" is a machine running on top of a second machine, e.g. a "simulated" machine running on top of a physical machine. A virtual machine is usually a natively-compiled "host" program which interprets and executes a second program made up of instructions defined by the creator of the VM.

A natively-compiled program is a chunk of low-level code generated (from source code in some language) to run on a specific architecture, made from a specific set of instructions which the architecture supports. This is why different c++ compilers are required for different operating systems/CPUs. A program compiled to run on a VM usually takes the form of "bytecode" (also compiled from source code in some language), which doesnt care about the specific physical architecture it is running on - the VM itself is compiled for various architectures, and executes the correct architecture-specific code "on behalf" of the program running within the VM. The bytecode instructions which the VM recognises are often more high-level, for example "Add X days to date Y" or even something like "Draw image X at location Y" (how high level these instructions are depends on how general-purpose the language supported by the VM is designed to be.

So a VM is effectively a program which "runs" another program inside of itself, by reading an interpreting instructions/commands made up by the developer of the VM.

This could be applied to your project in a couple of ways -

[list][*]You can embed the VM for an existing language like Lua, generating Lua code and handing it off to the Lua VM to execute for you - you provide Lua with "hooks" into your own code to allow it to call functions to draw stuff etc.[*]You dream up your own set of instructions which you think are flexible enough to allow a game to be expressed in terms of. Your front-end tool ultimately generates a set of instructions in the instruction set you have defined - often intermediate representations of the program (or game in your case) are used before it is "compiled" into the final instruction set. You then implement a "back-end" VM which allows such a game to actually be executed by interpreting the instructions and doing whatever is necessary to "execute" each one[/list]

Share this post


Link to post
Share on other sites

This topic is 2481 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.

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  

  • Forum Statistics

    • Total Topics
      628663
    • Total Posts
      2984111
  • Similar Content

    • By arash khalaqhdoust
      hey guys i hope you doing all well. last night i released my first game in google app store, i really appreciate you guys  to download it. and share your reviews about it
      the idea of game comes from mini hackgame of Bioshock.
       link of download:
      https://play.google.com/store/apps/details?id=com.RVBinary.piperist
      many thanks
    • By ForgedInteractive
      Who We Are
      We are Forged Interactive, a small team of like-minded game developers with the sole purpose of making games we love! Currently, we're progressing very quickly with our first project and there are plenty of opportunities and work for new interested programmers. With this project, our development platform is Unity 5.5.2 and C# as our behavioral language. Since this project is our first release, the game itself is a smaller project though progress is moving quickly. We are looking to finalize the current project and get started on future projects in the near future and are expanding our team to do so.
       
      Who We Are Looking For:
      Programmer Level Designer  
      About the Game
      Ours is the tale of two siblings, thrown into a world of chaos. Living in the shadow of their parents' heroic deeds and their Uncle's colorful military career, Finn and Atia are about to become the next force to shape our world. How will you rise through the ranks of Hereilla and what will be your legacy? Once defeated your enemies turn coat and join you in your adventures. Players can enjoy a range of troops and abilities based on their gameplay style which become more important as maps introduce more challenging terrain, enemies and bosses. Strong orc knights, dangerous shamans, and even a dragon are out on the prowl. Knowing when to fight and when to run, and how to manage your army is essential. Your actions alone decide the fate of this world.
       
      Previous Work by Team
      Although we are working towards our first game as Forged Interactive, our team members themselves have worked on titles including and not limited to:
      Final Fantasy Kingsglaive FIFA 2017 Xcom 2 Civilization  
      What do we expect?
      Reference work or portfolio. Examples what have you already done and what projects you have worked on academic or otherwise. The ability to commit to the project on a regular basis. If you are going on a two-week trip, we don't mind, but it would be good if you could commit 10+ hours to the project each week. Willingness to work with a royalty based compensation model, you will be paid when the game launches. Openness to learning new tools and techniques
       
      What can we offer?
      Continuous support and availability from our side. You have the ability to give design input, and creative say in the development of the game. Shown in credits on websites, in-game and more. Insight and contacts from within the Industry.
       
      Contact
      If you are interested in knowing more or joining, please email or PM us on Skype. A member of our management team will reply to you within 48 hours.
       
      E-mail: Recruitment@ForgedInteractive.com
      Skype: ForgedInteractive
       
      Regards,
      David, Colin and Joseph
       
      Follow us on:
      Facebook: https://www.facebook.com/ForgedInteractive/
      Twitter: @ForgedInteract
      Youtube: https://www.youtube.com/channel/UCpK3zhq5ToOeDpdI0Eik-Ug?view_as=subscriber
      Reddit: www.reddit.com/user/Forged_Interactive

    • By dell96
      I'm trying to make my first project but I'm stuck i don't know how to make my crate to start to spawn again when i hit the start button after i die.
      hoping someone can help!!!
      Crate.cs
      CrateSpawn.cs
      Cratework.cs
      GameController.cs
      GameManager.cs
  • Popular Now