Forum > Games

The plumps - a small RTS game in Lazarus

<< < (2/7) > >>

Tomi:

--- Quote from: furious programming on March 19, 2022, 06:59:30 pm ---Use SDL — it is super simple to use and quite powerful. Dealing with LCL limitations in the terms of creating game is a waste of time.

--- End quote ---
Hello Furious!

Yes, SDL and similar tools makes game developing easier, but I'm still too green for this and I just use basic Lazarus possibilities for games in first times. Then I will try Allegro and Castle Game Engine if necessary.

Seenkao:

--- Quote from: Tomi on March 20, 2022, 09:27:49 am ---Is there an optimal value to correct speed at all computers?

--- End quote ---
Для этого каждый "шаг" основного процесса проводят соответственно прошедшего времени. Вычисляют deltaTime прошедшего времени данного цикла и герой (и всё окружение) двигаются соответственно данного deltaTime. И тогда на разных компьютерах это будет работать примерно одинаково.
google translate:
To do this, each "step" of the main process is carried out according to the elapsed time. The deltaTime of the elapsed time of the given cycle is calculated and the hero (and the whole environment) move according to the given deltaTime. And then on different computers it will work approximately the same.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---prcedure proc(dt: double);begin  Heroes.X :=  Heroes.X + Heroes.Speed * dt / 1000;    // 1000 msend;

furious programming:

--- Quote from: Tomi on March 20, 2022, 09:34:09 am ---Yes, SDL and similar tools makes game developing easier, but I'm still too green for this and I just use basic Lazarus possibilities for games in first times.
--- End quote ---

You will always be ”to green” for this until you finally try — nobody was born with such knowledge and skill.

When I decided to make a game using SDL myself, I didn't really know how to use this library either. However, it is so easy to use that I had no problems programming other things. At most once in a while, by trial and error, I slowly came to a solution. I suggest not to waste your time on LCL to build games, because it is not suitable for creating games for many reasons, including the most important:

* no Direct3D and OpenGL support
* unable to use GPU for rendering textures
* no exclusive video mode support and available screen resolutions
* absolutely no support for sound mixer and playing multiple sounds at the same time
* lack of support for game controllers and their full functionality
* lack o V-Sync supportWhat I mentioned above are the basics, without which creating even a simple game will be inconvenient, the game itself will be very limited, and its performance will be very low (software rendering is horribly slow in compare to GPU rendering). As you can see, it doesn't make much sense.

Whether you want to make a tiny game or a bigger one, use the library dedicated to their creation. It does not have to be SDL, but it is important that it has all the functionality to create full-fledged video games. However, if you are interested in creating a 2D game, I strongly advise you not to use 3D engines for this purpose, because it will significantly complicate the implementation, and you will get discouraged very quickly.

Use something small, light, functional and, above all, supported at all times. I suggest SDL because it meets all the requirements and is great, but it can also be Allegro, because it's the same shelf. In case you ever get tempted by SDL and have questions, I will be happy to help. I've learned a lot over the last year so I'll be able to help a bit, especially when it comes to basic (key) issues.


--- Quote from: Tomi on March 20, 2022, 09:27:49 am ---Is there an optimal value to correct speed at all computers?
--- End quote ---

You have several solutions.

The first is to use delta to calculate motion using interpolation. Thanks to this, the game will run at the same speed on every computer, but the very big downside is that it will eat up all the available power of the CPU core. In the case of small games that do not have complicated logic and long-lasting frame rendering, this solution is weak.

The second way is a constant framerate and pauses between generating frames. The current time is taken, the frame is generated along with the rendering, and the time is retrieved again. Based on the two times, the number of milliseconds it took to generate the frame is calculated, the waiting time for the next frame is calculated and the function is called, which freezes the thread (Windows.Sleep, FPNanoSleep, SDL_Delay, etc.). This allows you to easily handle logic (no delta), frames are generated at regular intervals, and the process only uses as much power as it needs. It is a simple, energy-saving solution, but not very precise.

The third solution is V-Sync support, i.e. generating and displaying frames in accordance with the screen refresh rate. In this case, you also need to use delta-time, but timing and waiting for the generation of next frames is implemented on the API side of the GPU, so you do not have to program anything yourself — the intervals will be performed automatically. The solution is easy to implement (e.g. using SDL) and energy-saving and solves the screen tearing problem.

The fourth solution is a constant framerate (independent of the screen refresh rate), no delta-time, but precise measurement of the time between generating frames. Similar to the first one given, but the difference is that the intervals should be performed with more precision than the millisecond. After measuring the waiting time between frames, a larger portion is waited first using eg SDL_Delay (milliseconds) and the remainder waited using busy waiting. Thanks to this, the framerate will always be what we want (super-precise), no matter how little time you have to wait between frames. If you need inspiration, I implemented such a clock in my game called Fairtris (unit Fairtris.Clock.pp). This solution is also simple and energy-saving.

Of course, there are more ways and it all depends on what we really care about.


It should be noted that no matter if we want a constant framerate or a variable (matched to screen refresh rate or completely dynamic), using delta is a good idea if we want to use the slow motion (or accelerated motion) effect in the game. Without delta, it cannot be done other than changing the game framerate or doing strenge things with game logic, which is a very poor solution. The playback speed of the game should be independent of the framerate and programmed in such a way that it is easy to manipulate it.

AlexTP:
Copied the good comment to the Wiki, https://wiki.freepascal.org/Game_framework#Using_LCL_for_game_development

Seenkao:

--- Quote from: furious programming on March 20, 2022, 11:44:41 am ---I suggest not to waste your time on LCL to build games, because it is not suitable for creating games for many reasons, including the most important:

* no Direct3D and OpenGL support
* unable to use GPU for rendering textures
* no exclusive video mode support and available screen resolutions
* absolutely no support for sound mixer and playing multiple sounds at the same time
* lack of support for game controllers and their full functionality
* lack o V-Sync support
--- End quote ---
Не надо путать людей. Есть очень немало решений для одновременного использования и LCL и OpenGL/DX. Их можно увидеть в соседних топиках и на вики Freepascal. На немецком форуме почти все уроки по OpenGL сделаны под LCL. dglOpenGL.pas - позволяет работать с LCL в Windows без особых знаний создания окна/контекста OpenGL.
google translate:
Don't confuse people. There are quite a few solutions for using both LCL and OpenGL/DX at the same time. They can be seen in neighboring topics and on the Freepascal wiki. In the German forum, almost all OpenGL tutorials are made under LCL. dglOpenGL.pas - allows you to work with LCL on Windows without much knowledge of creating an OpenGL window/context.

* tutorial wiki eng.
* dglOpenGL tutorial Deutsch
* Metal, OpenGL demos
* GLScene
* GLEngine2D - based on dglOpenGL. Deprecated. But it works.
* Free Pascal Game EnginesДумаю я даже не смогу полностью осветить эту тему. И большой шанс, что я что-нибудь упущу. LCL так же можно использовать и с SDL, Castle Game Engine, PGF, Apus Game Engine, ZenGL и многими другими движками.
Подключение контроллеров, вообще не зависит от того что мы используем. Для этого надо просто использовать нужные библиотеки. Зачастую, которые уже идут с игровыми движками. И так же можно использовать в LCL.
Со звуком так же, ни кто не запрещает использовать одноканальный/многоканальный звук. Всё это предоставлено в соответствующих библиотеках. И так же можно использовать в LCL.
Вы очень сильно вводите в заблуждение людей!!!

google translate:
I don't even think I can fully cover this topic. And there's a good chance I'll miss something. LCL can also be used with SDL, Castle Game Engine, PGF, Apus Game Engine, ZenGL and many other engines.
Connecting controllers does not depend at all on what we use. To do this, you just need to use the necessary libraries. Often that already come with game engines. And it can also be used in LCL.
With sound, no one forbids the use of single-channel / multi-channel sound. All this is provided in the respective libraries. And it can also be used in LCL.
You are very misleading people!!!


--- Quote from: furious programming on March 20, 2022, 11:44:41 am ---What I mentioned above are the basics, without which creating even a simple game will be inconvenient, the game itself will be very limited, and its performance will be very low (software rendering is horribly slow in compare to GPU rendering).

--- End quote ---
Единственно по какой причине это не подходящий вариант, это если у вас высоконагруженное приложение. Тут я частично согласен!
На простых играх это практически ни как не скажется.
google translate:
The only reason this is not a suitable option is if you have a highly loaded application. Here I partly agree!
In simple games, this has almost no effect.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version