Skip to main content
GameDev.net gamedev.net
🔒 Locked

Game engine in C and open source, The Box, structural programming

Started by jdc Dec 22, 2019 at 10:49 AM 129 replies 256.9k views
Original Post
jdc
jdc

I notice a couple of people asking for non standard engines, so i decided to make this topic.

This is not a personal thing there are several reasons for this :

One is code automation, if you using Unity3D or Uneal Engine, they don't do code automation for you because if they do, can't sell lather the engine if one person can make all the projects with just a couple of clicks.

Another thing. To do a engine in C is because, all languages can communicate with it and is very high performance, much more then C++ because of large objects waste a bit of data.

The main thing is to automate code, click and the engine do all the work for you.

It uses file objects instead of memory objects this way it can have high performance, with out using to much memory. Still can become maintainable.

C will become to large? Due to file object not that much, it have zero repetition or close to it. Still the project is large, but it can be develop by the community i just setting the structures. Maybe lather ask for help in schools, in company's open source, etc... .

Another thing if is not open source people can't help.

Is not an engine, but a development software.

I plan to release version 0.0.2 with much more info. First version was only the structure. for 2º planning to have a couple of tools working. You can follow the page on Facebook. Is posted more detail on the objects on "free game dev", but is down at the moment.

https://wwwtodo?modal=admin_todo_tour

bzt
bzt
jdc said:
It uses file objects instead of memory objects this way it can have high performance, with out using to much memory

This won't work. Using files won't be nearly as performant as using memory, simply because files are stored on storage, and SSD or not, storage is MUCH slower than RAM. Always. Not to mention the fact that CPU can't access storage data directly, therefore you need to load the files into RAM anyway, and there goes your "high performance" down on the sink. Google Memory-Hierarchy if in doubt. You'd need a computer made of memristors for this to be fast, it simply can't be done with a computer using classic memory architecture.

Why are you so afraid of using memory? That was the '80s. Today's computers have plenty of it. Even a mobile handheld has Gigabytes of RAM, long gone the days when you had to process files with limited buffers.

Otherwise nice idea!
bzt

jdc
jdc

You sure?

Quake 3 online is still one of the most fluid games. Barely there are any loss of frames, and is online. Is build in C. You can have this kind of fluid today only in a top computer.

ttps://www.youtube.com/watch?v=laVpV1PFziw

Compare to unreal tournament the amount of frames loss. and is build in C++

https://www.youtube.com/watch?v=4vHZcZJTegQ

The logic says other way, the lower the language faster it is because is less nested. High languages are very nested that's way they are slow, process large amount of information.

PHP is extremely slow it can only handle 2 or 3 services.

You are probably saying that it may gain in graphic effects, because they evolve and are process in graphys card, so it does not have that much effect maybe. Is that way but still you gain a lot in low level language.

JoeJ
JoeJ
jdc said:
you gain a lot in low level language.

You would need to back this claim with some profiling results and more detailed examples, currently it sounds more like a baseless prejudice. Some examples:

Can you compile a C program with both C and C++ compilers, and get significant performance difference?

Can you identify which features of C++ are 'slow' / have hidden costs? (e.g. memory overhead / runtime perf cost of inheritance, virtual functions etc.)

Can we in the end, assuming we are aware of those things, make an advantage from C++ even if we aim for highest performance? (Thinking of abstractions like templates or functors that bring lots of flexibility, make it easier to write reusable code without adding perf costs.)

Are there some examples of C++ features missing from C where C++ is faster because of that? (Guess not really, it's just more work with C, but more code -> harder to maintain)


In the end it remains a matter of personal preference, and performance differences might be more related to compilers than to language. But to make a decision, you have to know both options very well, and only then you can make recommendations to other people. If that's not the case, you can only do more harm than good.
Also there is no more need for another C vs. C++ flame wars, now with scripting languages being the true enemy, haha :)


jdc said:
One is code automation, if you using Unity3D or Uneal Engine, they don't do code automation for you because if they do, can't sell lather the engine if one person can make all the projects with just a couple of clicks.

Sounds interesting, but what do you talk about? What do you achieve with code automation?

mr_tawan
mr_tawan
bzt said:
jdc said:
It uses file objects instead of memory objects this way it can have high performance, with out using to much memory

This won't work. Using files won't be nearly as performant as using memory, simply because files are stored on storage, and SSD or not, storage is MUCH slower than RAM. Always. Not to mention the fact that CPU can't access storage data directly, therefore you need to load the files into RAM anyway, and there goes your "high performance" down on the sink. Google Memory-Hierarchy if in doubt. You'd need a computer made of memristors for this to be fast, it simply can't be done with a computer using classic memory architecture.

Why are you so afraid of using memory? That was the '80s. Today's computers have plenty of it. Even a mobile handheld has Gigabytes of RAM, long gone the days when you had to process files with limited buffers.

Otherwise nice idea!
bzt

@bzt mentions a concern regarding file objects, while @jdc response with C++ as a high level language. Did I miss something ?

jdc said:

You sure?

Quake 3 online is still one of the most fluid games. Barely there are any loss of frames, and is online. Is build in C. You can have this kind of fluid today only in a top computer.

ttps://www.youtube.com/watch?v=laVpV1PFziw

Compare to unreal tournament the amount of frames loss. and is build in C++

https://www.youtube.com/watch?v=4vHZcZJTegQ

The logic says other way, the lower the language faster it is because is less nested. High languages are very nested that's way they are slow, process large amount of information.

PHP is extremely slow it can only handle 2 or 3 services.

You are probably saying that it may gain in graphic effects, because they evolve and are process in graphys card, so it does not have that much effect maybe. Is that way but still you gain a lot in low level language.

The thing is, you can write equivalent or close, performance-wise, to C in C++. In fact you can just write C and compile the code in C++ compiler, and it should be just fine in most case. ... Interfacing with other languages are also the same story, if you expose C interface of your C++ code, then those language should be bind-able to the engine without much issue I think.

Anyway if you're all about the performance, then go ahead. You can go even further by using only ASM I think. The fact that you plan to use file objects indicates otherwise, and in this case even PHP should give you around the same performance (as things are bottlenecked by the disk I/O anyway).

http://9tawan.net/en/
bzt
bzt

Hi,

Yes, my concern was primarily about file objects vs. memory, and yes, I'm absolutely sure about that. As @mr_tawan pointed out, disk IO is the bottleneck (and the fact that the CPU can't access data on disks directly, you must load them into memory first, so even if it wasn't for the disk IO there would be still an overhead).

Usually a properly written C code is faster than C++ or PHP, however you can't say that in general. For example an object lookup code in PHP could utilize the built-in array index hashing, while a C implementation could use an O(n) lookup, in which case the PHP version would always be faster. Therefore as @JoeJ suggested, you should ALWAYS do profiling, before you do any claims. And again, only certain implementations can be compared, not languages in general. That would be like saying yellow cars are faster than blue cars. Nonsense, only a certain yellow car can be compared to a certain blue car.

I for one welcome the idea of writing it in C instead of C++, but that's just a personal preference. I had to fix way too much C++ code written by rookies over the years. To my findings only experienced programmers dare to use C, while C++ is much more likely chosen by seasoned programmers, therefore there are lot more high quality C code on the net than C++. But this has nothing to do with the languages itself, and my experience is not representative in any way. And just because I was unfortunate enough to struggle with lot of badly written C++ code definitely doesn't mean that a skilled C++ programmer can't write a good code, or that a seasoned C programmer can't write a bad C code. Same stands for any scripting language: it is much more important how experienced the programmer is in the given language than what that language actually is.

Cheers, and Merry Christmas to you all,
bzt

Hermetix
Hermetix

I disagree different types of languages can't be compared to different types of colors. An interpreted language will always be slower than a compiled language. The type of implementation is irrelevant because we are assuming the algorithms used have similar time complexity. This is why using Python for example for something that requires low latency such as games or stock trading would be a bad choice.

I also disagree that C++ tends to be used by "rookies" as opposed to C. That would be Python or Visual Basic. C programmers are usually nostalgics, or people who like to program low level stuff in smaller scale projects. C++ offers more room for abstraction and this is required for large projects such as games or game engines. Is it easier to misuse? Maybe but that does not mean these programmers are rookies. It just means that they might not use all of its numerous features well.

Unity, UE4 and Godot are all written in C++ for this very reason: because it lets you design abstraction well and is also very high in performance. Mastering it is also very difficult because it lets you do so much. Stroustrup said it himself that it is so powerful that IF you shoot yourself in the foot with it, you actually blow the whole leg off. Writing an engine as big as UE4 in C for example could be done but C++ is a better choice for the reasons I gave. Abstraction is very important but a bad abstraction can be worse than no abstraction at all. But again we are supposed to compare oranges with oranges and apples with apples, referring to comparing programmers who actually know what they are doing.

Merry Christmas to you too and everyone.

bzt
bzt
Hermetix said:
I disagree different types of languages can't be compared to different types of colors.

You have missed the whole point. I wasn't comparing colors. I was comparing speed of cars, read back by post.

Hermetix said:
An interpreted language will always be slower than a compiled language.

Claim without any proof, which is not surprising as the claim is wrong in the first place. Have you read what I wrote? Consider an O(n^2) implementation in C and a O(1) in PHP of the same algorithm. The scripting language version of that algorithm will always run faster, regardless to the interpreter overhead.

Simple homework for you: implement unique array elements with bubble sort in C/C++ (natively, without any libraries, no "#include" allowed). Then implement the same using array index hash and ksort() in PHP (natively, without any extensions or additional classes, "include", "require" or class autoload not allowed). Generate a million test numbers, feed that list to both implementations and measure which one will throw out the duplications and sort the numbers faster.

Go ahead, do profile both!

Hermetix said:
I also disagree that C++ tends to be used by "rookies" as opposed to C.

You may disagree but under no circumstances can you deny my personal experience :-)

Also, how would you explain "It just means that they might not use all of its numerous features well." In my vocabulary that reads as they are not experts of the language, which was exactly my point when I said "it is much more important how experienced the programmer is in the given language than what that language actually is".

Cheers,
bzt

JoeJ
JoeJ
bzt said:
Simple homework for you: implement unique array elements with bubble sort in C/C++ (natively, without any libraries, no

That's not fair. Why can use ksort but not standard library?

And it's also pointless, because afaik the php interpreter is written in C.


As long as we talk about games, which means realtime and low level optimizations being critical, it's quite ok to say interpreted languages are slower IMO.

(Surely time complexity is more important than that, but that's obvious.)

Hermetix
Hermetix
bzt said:
You have missed the whole point. I wasn't comparing colors. I was comparing speed of cars, read back by post.

I understood what you meant, I mentionned speed right in the sentence after. IMO, you could have used another analogy such as comparing an SUV with a sports car. Now that would have been futile since you can't say which is "better" in their general use, but speed? You sure can say which is faster.

bzt said:
Claim without any proof, which is not surprising as the claim is wrong in the first place. Have you read what I wrote? Consider an O(n^2) implementation in C and a O(1) in PHP of the same algorithm. The scripting language version of that algorithm will always run faster, regardless to the interpreter overhead.

Again, I got you meant. I said that the time complexity is assumed to be the same. You have to compare similar implementations to say which language executes code faster.

bzt said:
You may disagree but under no circumstances can you deny my personal experience :-)

Well in my own experience, I tend to see people use other languages before C++ because it looks intimidating to them.


bzt said:
In my vocabulary that reads as they are not experts of the language, which was exactly my point when I said

Well C++ is a multi-paradigm language, you can program structurally with it, or object oriented. It has so many features that mastering all of them is almost impossible. But it's a lot easier to master one paradigm in this language and use it well than be able to use it well in all ways possible.

But to go back to the OP's point, how many things can you do with UE4 for example as opposed to having to read 160k+ lines of code such as Quake 3's source code? You can do much more with UE4 and it's not just about code automation. John Carmack switched to C++ to make DOOM 3 for a reason, and it is very probably because he needed a higher level of abstraction to make a bigger game in terms of lines of code. And if you want to compare Unreal with Quake, Unreal started with better graphics (16 bit textures) so that takes a toll on the performance. And its code architecture is what lead to UE4 probably because I doubt that he rewrote the engine from scratch after each new game.



Jeff1da
Jeff1da

[Hijack deleted by moderator.]

jdc
jdc

Attempt to replay to all

If you people like C++ go ahed, debate C++ in post's, or topic's, how good it is and how much you like.

Was for PHP, yes, C as similar sintax to PHP i start doing all thing in PHP and learn how to do a procedural engine and manage code so bringing that experience to C.

Only on The box version 0.0.2 more things will be available for people to follow.

A engine in C is not bad, was some one mention in a Ogre3D topic that a engine in C is needed because all can communicate with C.

It's a matter of syntax and large engine can be programmed in C, was long you know how to inherit stuff, is mainly the only thing you need to avoid repetitions.

How to automate, generate the file project, and functions automacatly for users.

Free game dev is up you can follow all posts on objects, tools, planning etc... in there.

For example working in this objects:

  • color.h
  • path.h
  • control.h
  • grahics.h
  • variables.h
  • interface.h
  • image.h
  • ...

Converting all things to objects, the problem is that most software attempt to put every thing in one file which is bad. Let's say that you only need colors, or variables for next program. A lib png, may use colors and variables. If you have your variables and colors in a jpg lib, you can't reuse, you may not need to add jpgs to a project.

You can program a large program was long you don't repeat your self.

How i do it: Inherit file objects, the point is to declare every thing one time and reuse.

The syntax will be like base C.
color_text = blue;

color_background = blue;

use_colors_defined_before ();

very similar to C base functions, it uses globals variables, to pass information in a object style

char c;

printf("Enter character: ");

c = getchar();

it assumed a printf function.

jdc
jdc

forget recruit for projects:
may advice work in a open source engine, then all can program to it. Much more easy then do individual projects, then ask for help.
Create templates of projects, something i'm doing for this projects, people will only need to edit. Will save huge amount of time.

jdc
jdc

@Hermetix C is very intimidating and i have many years of programming procedural code LOL.

jdc
jdc

Write a proper tutorial:

How the syntax looks line in this project The Box.

Works like Html CSS, but is made with File objects in C.

Values will be persistent until new is added.

include “color.h”

color_text = "black";
color_background = ""white;
button1();
button2();
button3();
color_text = "green";
button4();

All buttons will have text black and background white. Button 4 will have white background and green text. Only one property is updated.

It's the same was CSS. Values are persistent until a new value is add that override part of the values.

- How it's done

variables are global, that's how it's done. The color_ is a reference to the object color.h, which is done manually is not called in code.

the color.h will simple have global variables.

color_text;
color_background;

To change font. font.h will have global variables on that.

font_weight;
font_italic;
font_style;

A example with the font

color.h
font.h

color_text = "black";
color_background = ""white;

button1();
button2();
button3();

color_text = "green";
font_weight = "bold";
font_style = "arial";

button4();

A costume button 4 with a font arial, bold weight, and color text green and a inherit background color white;

-------------

The same can be applied to functions. At the moment i don't have a real example will make one for the tutorial. “Costume_function”.

color.h
font.h
interface.h
costume_function.h

color_text = "black";
color_background = ""white;

button_costumized(); addeds : border, solid, 1 px;
"
property_border_style: solid;
property_borde_width: 1px;
"

button1();
button2();
button3();

color_text = "green";
font_weight = "bold";
font_style = "arial";

button4();

All 4 buttons will have a customized border. First 3 will have: a text color black and background white. 4º button will have a customized style was before. text color green, font weight bold and a different font arial.

No variables are passed to functions at any time, only when needed or variables repeated because, they are inherited, only one time will a variable be declared.

A FILE object is declared only one time in file.h

file.h
FILE * FILE_pointer;

A example with the file pointer.

color.h
font.h
interface.h
costume_function.h
file.h

open_file(); // Get styles

"
receives FILE_Pointer; From file.h
"

color_text = "black";
color_background = ""white;

button_costumized(); addeds : border, solid, 1 px;
"
property_border_style: solid;
property_borde_width: 1px;
"

button1();
button2();
button3();

color_text = "green";
font_weight = "bold";
font_style = "arial";

button4();

open_file(); // Get styles for a menu

"
receives FILE_Pointer; From file.h
"


The style is the same was previous example, now the openfile() is using the same file pointer which is a object variable, if needed to store values, which are a less thing since most time we will be doing something and outputting the values. Are stored in arrays, structures, or files, with the values and passed to the functions, with the same thing global variables.

The variables with the stored information have plural names, to be different from objects, which are single abstraction. For example “char menus”; will store information that is needed to call back. Maybe a menu position, to know which are where. But since many information is in files, object abstraction is probably enough.

Store information and load dynamic information

tool.h
interface_index_keys = {"interface_id", "menu_position", “text_color”, “background_color”, “”};
“information_menu.txt”
20, 1, black, white;

The information will be in txt, files, it will make it really dynamic, can chance any thing in the software. The format choose a simple keys to load and to map, if you see it have the same name of variables. and files have limited information to speed the search process.

The keys map the file, and will also work with simple idex, which are separated files with only the id's to speed search of information in files. Like a database work but only with txt files.

With this format we can load a hole project from a txt file, and probably will not consume many resources.

Domarius
Domarius

If your reasoning is that the lower level you go, the faster your game will be, why stop at C, why not program in assembly?

Apparently C# is just as performant as C++ for most software development except for very low level rendering code etc.

There was a time when choosing to program in assembly gave you performance benefits that were worth the time it took, but that time eventually passed, a long time ago, and everyone moved to C.

And now technology has progressed to the point where you most probably shouldn't be getting bogged down with C for your whole engine because you won't get enough performance back to justify the time you'll spend when you could be using C++, or better yet, an existing engine. They allow you to deploy to multiple platforms, so you can put your game not just on Windows, but on consoles like the Nintendo Switch, mobile phones etc. and actually make money and make a living out of it. Good luck doing that in C while rolling your own engine!

For local multiplayer retro themed games, visit Domarius Games.
VoxycDev
VoxycDev

Domarius said:
If your reasoning is that the lower level you go, the faster your game will be, why stop at C, why not program in assembly?

Because modern C/C++ compilers optimize the machine code they generate so well that unfortunately it ends up faster than any human-written assembly.

jdc
jdc

Thanks, assembly is to much, but i though on it, since C can communicate with other languages. Maybe is a option, In Graph App, they delegate to external programs part of the services which is something i was not aware it was possible. Only programmed in PHP for a good time so it was only server. When you are at the computer, you can do much more things. Like using isolated programs that communicate which other.

You can have several langues in a project think Blender is part in C, assembly and in python.

Graph APP team have something in assembly, you can check that if you interested in Assembly, and in the Box project.

Tycoon, was a game build in assembly only because at that time they needed high performance to have that many stuff loaded in to a game.

The project is not just for high performance is for educational purposes also. We don't have a C program that allow people to learn. And if tomorrow a new machine/console, come out and want more support is not dependent in this libraries can write is own.

Raspebarrie Pi a machine that could use well on this software and also Linux which is all build in C, you can have high compatibility if you write something in C.

C++ can do all that? Yes, but is very depend on library's if you chance or want to work in another OS you need to do things in windows first. Which means even if performance is not affect which it is. Can't play a game i made with Unity 3D but can play world of warcraft. And is very big, a simple map 4 wall and 2 characters 400 mega. Most web games for unity 3D can't play them.

To conclude the topic : performance is affected, size is affected, operating system is affect, and machine/computer is affected.

VoxycDev
VoxycDev

Would like to see some source, screenshots and possibly a demo for The Box. Using C only is a nice idea. I have considered sticking to C as well, but I find the C++11 STL classes such as map and vector too useful. Maybe there is a C library that emulates them? The cool things about C is that a C compiler is very small, and can be made to run on embedded devices. What kind of doors does this open up for games?

Let's suppose you released your games as physical devices, like handheld games or arcade machines, C would be the way to go. Although most new arcade machines do use Unity, not all do and those are the most unique.

Let's suppose you decided to wipe the slate clean and develop your own graphics hardware architecture that pertains exactly to your game. What if you invented some new way of drawing that does not use pixels or polygons? C would be the way to go. Look at what Ken Silverman is doing with VoxieBox.

I am in favor of not an open source engine, but a set of modular open source libraries that you can plug in and out of your project depending on what you need, whether C or C++. Let's say you have no code of your own and you want a scene editor and a bloated C# VM with tons of pre-made layers for everything, you can import that. Let's say you don't and you only want high-performance rendering because you already have your own editor and scripting, then you only import that part.

jdc
jdc

Tutorial Post, on software functionality

At the moment you have to pay for all this, and the project will do all this things free.

first stage – design the project with the design tools, design document, game lore tool, add : history and characters to the game. Using build concepts available.

Second stage - template , load a previous template with the basic project on that theme, for example a isometric game.

third stage - have libraries to load a basic art to structure the project, for example a 3D low polly library. Which make all the game playable.

fourth stage - add functions automatically, from code snippets or create own functions from standard functions tool without using the code editor.

fifth stage – design the basic stuff, like levels. Simple audio/video edit, interfaces.

six stage – access the market for : founding, jobs, or help on the project

Seven stage – auto compile to platforms, without the need for knowledge on how programming

eight stage – publish to a free platform

nine stage – create the community with the social tools, also free. (You pay the social networks today indirectly at the cost of your privacy. Publicity)

*Servers if some one want to set up lather could also be added, for example for simple games. If the server is using the same libraries.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.