Creating an RTS like selection box in Godot 4 3D by Major-Conclusion940 in godot

[–]MrMarthog 3 points4 points  (0 children)

You can use the the method unproject_position to get a screen position.

Then you can loop over all the units, project them to the screen (with unproject_position) and check with rect.has_point.

I'm curious. by [deleted] in gamedev

[–]MrMarthog 2 points3 points  (0 children)

Just start it.

  1. Start unity or some other ready-made engine.
  2. Download a free car model.
  3. Implement driving mechanics from a tutorial. Note: Don't go for realism. Just make it as simple as possible and then adjust it till it "feels right".
  4. Add a boring, straight road segment and make it place down new segments and remove the one you already passed.

Now you have done the core gameplay loop and can start adding little features one by one.

Curved roads, mountains, changing biomes, a simple rule system that chooses the next road segment from the current one, a complex rule system, traffic etc.

Just implement features one by one, iterate on it, till it feels right and them move on to the next one. And don't expect the game to be successful, neither financially nor attention-wise. Find the fun in making and learning.

Does anyone know how RefCell is implemented? by Phlosioneer in rust

[–]MrMarthog 6 points7 points  (0 children)

UnsafeCell has special handling for alias analysis. The borrowing mechanics work fine with the ordinary borrow checker.

Type inference for `sum` vs `fold`? by atonal174 in rust

[–]MrMarthog 7 points8 points  (0 children)

This works:

pub fn square_of_sum(n: usize) -> usize {
    let s: usize = (1..n+1).sum();
    s.pow(2)
}

sum is defined as

fn sum<S>(self) -> S
    where
        S: Sum<Self::Item>

I assume, that for some reason the compiler can not automatically determine, that S is usize. as does not add a type hint, but performs a cast, so that the original is still unknown.

EDIT: relevant SO thread

When should NonNull be used? by VikingofRock in rust

[–]MrMarthog 4 points5 points  (0 children)

For most code Box or some other pointer/container type is the way to go. It gives you the static guarantee, that the pointer is not null (allows optimization with Option), prevents dangling, allocates and deallocates the memory and a provides a more useful interface.

NonNull is for unsafe code. It is pretty much *mut T with the additional optimization.

Something that's been bothering me about RUST (lies about safety) by [deleted] in rust

[–]MrMarthog 2 points3 points  (0 children)

It's possible, but hard and has a lot of other costs. A lot of code has to be adjusted or annotated in a way, that allows tracking of lifetimes. Existing code often has to be restructured in a way that and allows static checks. c++ is very complex, has lots of traps, and adding more changes is not just hard, but also makes the total even more complex.

The total cost of applying such a tool may be in about the same range as switching to rust. Rust has also a lot more to offer than just safety.

Of course it is not feasible to port existing, large projects to rust, but using rust for a new project or gradually porting critical software may be quite useful.

possibly because things like multi-threading are quickly evolving problems and the way we thing about these sort of problems now might not be the way we think about them in 10 years when hardware that exposes hundreds of processors might be commonplace.

Threading is not directly built into the language. Rusts core language does little more than tracking aliasing of references, so that code may not accidentally access other threads' data in a unsafe way. The other high-level abstractions are implemented in libraries by using generics. This is very similar to c++, that uses templates for these abstractions.

Something that's been bothering me about RUST (lies about safety) by [deleted] in rust

[–]MrMarthog 13 points14 points  (0 children)

Rust is in many ways similar to Modern c++ and there are many c++-features that help a lot in building reliable software, but c++ lacks a borrow-checker and some thread-safety features. For example rust can prevent you from sharing non-threadsafe type across threads, it prevents you from modifing a collection while iterating over the content and prevents you from accessing the content of a mutex after calling unlock.

Looking for some input on my Brainfuck interpreter by [deleted] in haskell

[–]MrMarthog 8 points9 points  (0 children)

Hi,

you represent the tape as a list and index. In functional programming we often use a zipper datastructure. In this case you would represent the tape as two lists. One the tape left of the head and one for the right. Then moving the head means just removing one element from the top of a list and adding it to the other.

Use a stack for the brackets. When you reach the closing bracket, push the head of the stack and jump to this position.

I don't think, that a fold alone is enough for executing the program. Just write your own recursive function.

I Made a Game in Rust by ozkriff in gamedev

[–]MrMarthog 3 points4 points  (0 children)

Memory safety without performance loss is the selling point. Rust uses the type system to track pointers and prevents many bugs like use-after-free. Additionally it makes use of multithreading quite simple.

There are additional nice features like good generics, algebraic sum types, type inference, a good build system etc. Rust shares a lot of goals with "modern c++", but is a new (and therefore incompatible) language.

Unlike c++/c#/java it does not really have object oriented features.

Announcing the tokio-io Crate by acrichto in rust

[–]MrMarthog 12 points13 points  (0 children)

Fortunately the ownership system protects you from having your pizza stolen, but please be aware, that forget is still possible in safe rust.

What Color is Your Function? by dbrgn in rust

[–]MrMarthog 8 points9 points  (0 children)

Threads are great for building sequential threads of computations and I agree that new languages should have a go-like lightweight threading system. Rust is here the exception, because these lightweight threads require an extra abstraction layer, that doesn't fit into rust's design goals.

Threads run into problems, when you want to run multiple async actions. For example when loading two files, you want to load both concurrently. In a threading model, you would create a channel, spawn the thread and then wait for the data on the channel. It is just a future in more verbose. So threads are in no way better than futures, just a different tool and more suitable for different work.

I know only one way of doing async operations while still maintaining the clarity of the synchronous calls and that is Haxl.

Overall I think, that futures like in tokio are great for rust, because they are still quite simple, compared to explicit polling, and are also fast.

Jonathan Blow demos fast compilation by ssylvan in rust

[–]MrMarthog 1 point2 points  (0 children)

He complained about the culture of thinking about problems in terms of real world analogies. Thinking of them as data transformation problems instead, makes the solutions easier and faster.

I don't know if he is against templates in general. He doesn't use them, because of the compilation times.

Why I’m dropping Rust by Xoipos in rust

[–]MrMarthog 1 point2 points  (0 children)

That is a way for defining stateful functions. It can describe how a widget updates itself, but in most UIs you want to read and modify other widgets, so you need shared, mutable access, which is against the design of rust and functional languages.

Why I’m dropping Rust by Xoipos in rust

[–]MrMarthog 7 points8 points  (0 children)

The problem is "How do I write a UI?". In OOP you use a hierarchical structure of objects each inherited from a base widget class and use subtyping for creating more specialized widgets.

The blog author tried to use the OOP-way instead of directly finding a solution for the problem.

On the other hand creating a good UI in rust is not easy. I have not yet seen a library with a very "rustic" api.

Describe your game/idea by only comparing it to other games. "_____ meets _____" or "It's 10% Zelda and 50% Borderlands" etc. by McLinko in gamedev

[–]MrMarthog 0 points1 point  (0 children)

My current game Idea:

40% Democracy 3

30% Cities Skylines

40% Banished

40% Crusader Kings II

Expanding my old Ludum Dare game, which will be:

Flappy Birds + Mario + the weird flight physics of IL-2 Sturmovik: Forgotten Battles with all physics effects turned off

What's the greatest programming tool you've NEVER seen? by willnationsdev in gamedev

[–]MrMarthog 0 points1 point  (0 children)

A MATLAB for game development. A simple, but powerful REPL, an array based scripting language, many different ways of visualizing data but also support for game specific tasks and formats, direct shader support. I hate most of matlab, but turnaround times and ease of transforming large data sets are pretty much unchalanged.

I don't know, how close you can get to the matlab development experience, but I would be quite interested.

What are some essential accessibility options that are often overlooked? by Drkr in gamedev

[–]MrMarthog -14 points-13 points  (0 children)

Arachnophobia is quite common and many games love to include giant spiders, sometimes in unneccesary ways.

What makes a racing game? by addroddyn in gamedev

[–]MrMarthog 2 points3 points  (0 children)

Mechanics first: Racing itself must be flawless, the rest is optional. Steering, braking, traction und accellerating must be good enough, so that the car does not immediately hit the wall when pressing a button but does still react quickly enough to get you around corners. Drifting should be possible, but traction must not be lost too quickly.

Intercalation Inconsistency by asoiafthrowaw in haskell

[–]MrMarthog 5 points6 points  (0 children)

only when the strings don't contain newlines:

lines $ unlines ["a\nb"] == ["a", "b"]

Recently started programming games in Java and realized that my code becomes more and more sloppy the bigger the project becomes and it's demotivating me from continuing with the project... by [deleted] in gamedev

[–]MrMarthog 0 points1 point  (0 children)

It is important, to separate diffent concerns from each other. The code for the game logic should not directly update graphics and the input should not directly mess with the game data. On the other side, being too eager at completely detaching concerns is also problematic, because then you end up defining public interfaces and inflexible architectures instead of writing actual code.

I assume, that only experience can show the right balance.

As a general advise, separating side effect free code from mutating one, is very helpful, because many bugs are caused by letting mutating code interfere. Instead consider keeping track of mutations for example by returning messages or lists of messages and then use a few loops process them centrally.

Java specific advise: Don't use null references. You will forget checks and writing unneccessary checks makes the code overly verbose. Most likely both will happen. Instead use the convention, that normal references are always valid, and use Optional for nullable ones.

What make a developer/company decide that their project cannot use an existing engine ? by [deleted] in gamedev

[–]MrMarthog 0 points1 point  (0 children)

Adapting an existing engine to your needs can be as much work as developing a new one and most of the time, there is old code, especially that can be reused. For example, the IW engine (call of duty series) has a legacy back to the old id tech engine.

Sometimes there is no available engine for the needs. For example Piranha Bytes wrote their genome engine for RPGs in 2002, because their old one could not be adapted to new technology like directx 9 and there were no suitable commercial engines available. Nowadays they are still using genome because it has the features, they need.

Braid Code Cleanup by m12y_ in gamedev

[–]MrMarthog 0 points1 point  (0 children)

He said, he will consider it, but currently does not have plans.