Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411491 Posts in 69371 Topics- by 58428 Members - Latest Member: shelton786

April 25, 2024, 03:46:40 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)General thread for quick questions
Pages: 1 ... 41 42 [43] 44 45 ... 69
Print
Author Topic: General thread for quick questions  (Read 135359 times)
oahda
Level 10
*****



View Profile
« Reply #840 on: September 21, 2016, 05:53:40 AM »

Not trying to persuade you to use C++ if you don't like it, but I thought I'd try and reply to some things nonetheless. c:

I completely understand your issues, and I don't disagree that C++ is rather messy and ugly because of its backwards-compatibility that prevents it from removing some unnecessary stuff when adding new alternatives.

The obvious answer is to pick a modern subset, but I see how conflicting resources from different time periods makes this difficult. Perhaps it's better to get a textbook focused on modern C++ than to read a bunch of scattered online material. One of the talks I watched recently did mention that there were plans to add compiler flags to disable deprecated stuff for those who don't want to use it anyway, but I don't know the current state of that.

Java is aggressively object-oriented so you don't have to pick from a dozen different progamming paradigms.
That's how it started out, and may be how it's still being marketed, but it's not really true. If you look at a comparison table over paradigms supported by various programming languages, Java and C# actually tick some boxes than C++ doesn't. Everything in Java may technically have to exist in the scope of a class, but one can still do a lot of the same things with it (plus a few more things, like reflection).

But this is the thing, with Java and C++ both having all these options... You said there are C++ veterans who still find new stuff. What that means to me is that that stuff isn't actually needed for much, because they've managed without it so far, right? And obviously if C++ is written just like C, the program isn't necessarily worse, right? Because then C wouldn't be any good. C++ offers a lot but you don't necessarily need much of it. Various applications have different needs. C++ is versatile to handle just about any use case out there.

So if you're going for C, you might as well just use C++ IMO, and subset it to, say, C with strings, RAII memory management and lambdas or something. Get some of the really handy additions that C++ has added without choking on all of it. But I mean, that's basically how I'd recommend anybody to learn C++ anyway. Don't try to understand or use everything at once. It's not necessary.

If you go for Java, you will probably have to subset that if C++'s wealth of paradigms is too much for you anyway, because like I said Java actually supports a lot of paradigms too. Tongue

It's also worth noting that some of the features I've found out about after years in C++ actually come from C, so they weren't even introduced in C++! Cheesy Like this, just the other day.

Also, if it matters to you, do remember that despite how Java has historically been marketed, C and C++ are in practice portable to more systems than Java.

As for personal preference, I've come to prefer C# to Java. It works outside of Windows thanks to Mono. I actually wrote a Mac application in C# with Xamarin this week. Attributes are amazing (Java seems to have something similar called annotations now, but I don't know how they work). If there's one feature I really want C++ to add, it's custom attributes like in C#.

But also don't forget that no language is perfect. C++ is my favourite, but it doesn't have everything I'd like that I know from other languages (attributes) and certain things I've come up with myself when designing languages of my own on paper to figure out what my ideal language would look like. So it's really about getting used to what a particular languages offers and working with it to the best of one's ability.
« Last Edit: September 23, 2016, 11:01:15 AM by Prinsessa » Logged

agedev
Level 0
**


View Profile
« Reply #841 on: September 21, 2016, 10:25:55 PM »

I'm so sick of C++.

I've been using it for a few months and I want to try something different. Right now I'm considering Java and C. Here's what I'm looking for:

  • Needed: 2D hardware-accelerated rendering, keyboard/controller input and sound.
  • Needed: Windows and Android support.
  • Highly wanted: Mac, Linux and iPhone support.
  • Highly wanted: Fragment shaders like GLSL.
  • Optional: Networking support.
  • Don't care: 3D rendering.

And yes, for the record, I understand all the implications of using both languages. Java is slower than C++ and isn't as popular in game development. C has manual memory management and a lack of OOP. From what I've seen, Java has JFrame, Java2D and LWJGL. C has Allegro, CSFML and SDL. Which of these would be the best choice for game development? Do they even support what I need? Are there any other good options out there?

Neither is the best choice for game development. They all, and others support everything what you want, and you can create remarkably good games in all.

The best choice is what you are familiar with. If you don't have any familiarity with anything, pick ONE platform and go with its standard language & library (E.g. iOS? Swift, Android: Java, Windows: C#).


Your concerns actually aren't issues that can be fixed with a different language (e.g. Java too slow? Almost always writing more performant code will give a bigger boost than switching to C++). And since the vast majority of code is interchangeable between c-based languages, I would argue none is 'easier' to learn and get something meaningful running.

On that note, if I were to attempt to hit all your bullet points starting from scratch, my choices would be C++ or HTML5. But that is entirely because of the long list of platforms and my familiarity with C++ (or well, if I can get it to run in browser, platform doesn't matter). Every other language would require too much investment from me in learning to do things 'just to get it to work' because I have never done it.
Logged
surt
Level 7
**


Meat by-product.


View Profile
« Reply #842 on: September 21, 2016, 11:29:19 PM »

  • Needed: 2D hardware-accelerated rendering, keyboard/controller input and sound.
  • Needed: Windows and Android support.
  • Highly wanted: Mac, Linux and iPhone support.
  • Highly wanted: Fragment shaders like GLSL.
  • Optional: Networking support.
  • Don't care: 3D rendering.
Haxe plus OpenFL or one of the other frameworks should be able to do all that and can target pretty much every platform under the sun. It is still multiparadigm though.
Logged

Real life would be so much better with permadeath.
PJ Gallery - OGA Gallery - CC0 Scraps
powly
Level 4
****



View Profile WWW
« Reply #843 on: September 22, 2016, 12:43:56 AM »

  • Needed: 2D hardware-accelerated rendering...
  • Highly wanted: Fragment shaders like GLSL.
  • Don't care: 3D rendering.
Just for the record, these criteria are practically equivalent.

There are some libs (SDL?) that do accelerated blits but that's an improvement only if you want to draw a few very large sprites with general affine transformations.

General graphics APIs are the way to go.
Logged
JohnsyJohnsy
Level 0
**


View Profile
« Reply #844 on: September 22, 2016, 06:19:49 AM »

Quote
Needed: 2D hardware-accelerated rendering, keyboard/controller input and sound.
Needed: Windows and Android support.
Highly wanted: Mac, Linux and iPhone support.
Highly wanted: Fragment shaders like GLSL.
Optional: Networking support.
Don't care: 3D rendering.

This list has not much todo with one  language over the other, this is what a game-engine offers,
Speaking about that, practically all half-decent game engines support all the things you want.

So i dont think this list will help you deciding what language to choose.
I'd just pick the language you're most comfortable in, and pick an engine to go with it.
Logged
DragonDePlatino
Level 1
*



View Profile WWW
« Reply #845 on: September 22, 2016, 03:08:50 PM »

Thanks for the input, everyone. I've put some thought into it, and I decided to go with C and a binding for SFML (CSFML). I've used SFML and other OpenGL-based libraries for a while now so I won't be completely starting from scratch. :D

So if you're going for C, you might as well just use C++ IMO, and subset it to, say, C with strings, RAII memory management and lambdas or something.

If worst comes to worst and I can't handle the manual memory management of C, that's likely what I'll end up doing. I'll go back to C++ but limit myself to the absolute basics like objects and strings. Maybe C++98. Until then, I'm very happy with C so far. I reimplemented part of my Entity Component System today. While not the safest method, a void* array accomplished the job as templates, variadic functions and static casting for storing my components in cache-friendly memory. Coming from C++, it feels liberating (and dangerous) working in a language where anything goes!

Haxe plus OpenFL or one of the other frameworks should be able to do all that and can target pretty much every platform under the sun. It is still multiparadigm though.

Hi surt! Big fan of your art. :D

Haxe looks pretty neat and the sheer number of supported platforms is great. I'll definitely consider that one in the future.
Logged

InfiniteStateMachine
Level 10
*****



View Profile
« Reply #846 on: September 23, 2016, 03:01:22 PM »

We don't really have a thread for general discussion do we?

Anyways I saw this post by a person who implemented the same game twice. Once in C++ and once in javascript. Technically the performance was pretty similar but in reality things like stutters etc make the game feel worse.


http://www.irrlicht3d.org/pivot/entry.php?id=1513

Logged

Cheezmeister
Level 3
***



View Profile
« Reply #847 on: September 23, 2016, 05:03:26 PM »

Orthodox C++, baby! All the goodness of C, no vtable headaches or <<><><<<><><><>>>> vomit, but you can sleep at night knowing +-*/ overloading and nullptr are there if you need them.
Logged

෴Me෴ @chzmstr | www.luchenlabs.com ቒMadeቓ RA | Nextris | Chromathud   ᙍMakingᙌCheezus II (Devlog)
oahda
Level 10
*****



View Profile
« Reply #848 on: October 07, 2016, 04:37:04 AM »

We don't really have a thread for general discussion do we?
I seem to recall there being a "neutral programmer room", but feel free to create one otherwise. c:
Logged

ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #849 on: October 08, 2016, 04:29:34 PM »

We don't really have a thread for general discussion do we?
I seem to recall there being a "neutral programmer room", but feel free to create one otherwise. c:

I found it buried 18 pages in. Seems like these things get forgotten once they fall off the first page: https://forums.tigsource.com/index.php?topic=17308.0
Logged

Manuel Magalhães
Forum Dungeon Master
Level 10
*****



View Profile WWW
« Reply #850 on: October 09, 2016, 05:59:19 AM »

That thread should be pinned imo.
Logged

oahda
Level 10
*****



View Profile
« Reply #851 on: October 09, 2016, 11:47:18 AM »

Dunno, I always overlook pinned threads like locked notice threads and never actually check them. I'm much more likely to check threads that actually move around when they pop back to the top.
Logged

Photon
Level 4
****


View Profile
« Reply #852 on: October 11, 2016, 06:46:03 AM »

For those of you who use entity component systems:

How do you handle construction of your entities? I want to use some kind of XML format instead of hard coding every "constructor" right into the code. I'm using Haxe, by the way. I can think of two extremes here:

Code:
<entity>
    <component class="PositionComp">
        <float name="x" val="0.0"/>
        <float name="y" val="0.0"/>
    </component>
</entity>

Haxe supports indirect constructor calls via supplying a class and a dynamic array of arguments. Here I would simply pull out the "class" attribute seen above and use that (after resolving the string to an actual class, of course) with the array I built from the following children nodes. This is the simplest implementation but probably has significant overhead from all the indirect constructor calls and, on static targets, the use of the Dynamic type for parameters.

The second option would be to have it resolve all the XML nodes directly, where we use the "class" attribute in something akin to a giant switch statement. We then have code that handles each specific component instance. But this sounds ugly and unwieldy to manage and, frankly, kind of defeats the purpose of having a streamlined format in the first place, especially if every new component type requires another couple dozen lines of code.

Thoughts? What I'm looking for very well could be a happy medium between the two.
Logged
bateleur
Level 10
*****



View Profile
« Reply #853 on: October 11, 2016, 06:56:51 AM »

Thoughts?

Best answer depends on why you're doing it.

* Elegance? Do it dynamically.
* Speed of development? Do it dynamically.
* Data readability? Do it statically (with switch, or similar).
* Extensibility? Do it statically.
* Maintainability? Don't do it at all.
* Stability? Don't do it at all.

Most of the time IME this kind of cleverness isn't worth it. Hardcoded constructors may be ugly and noisy, but the XML isn't really any better, it's just in a different file.
Logged

Photon
Level 4
****


View Profile
« Reply #854 on: October 11, 2016, 07:11:22 AM »

Speed of development was the primary motivator here. The general concept of ECS clicks with me from a development standpoint, but it can introduce a fair bit of monotony when trying to snap everything together. I personally prefer hardcoded solutions and generally avoid the Dynamic type like the plague (both for performance and type safety reasons.)

In short, I've been working with ECS for awhile now and I'm still trying to figure out the best way to cut through the fluff, or at least reasonably manage it. I have little intention of abandoning it because I really like its pros, but I'm willing to make tweaks to lessen the cons.

Edit: I gave this a little more thought...

I wonder if what I really need isn't a construction format that's super granular like above, but rather only accounts for the nuances between objects? As a small example:

Code:
<entity>
    <physics>
        <gravity val="no" />
        <static val="yes" />
    </physics>
</entity>

Its probably not necessary to tell the constructor that we want a positional/velocity/etc. component; we can just assume that. That XML will simply fill in details and specify "anomalies" that the constructor would otherwise receive as parameters (which keeps us from having a massive parameter count as more details are accounted for) and parameters can easily be omitted as well.

This format seems flexible while allowing me to handle the small details in a direct manner.
« Last Edit: October 11, 2016, 08:06:02 AM by Photon » Logged
oahda
Level 10
*****



View Profile
« Reply #855 on: October 11, 2016, 09:04:40 AM »

I've used an XML format like that and it worked fine. Parsed it recursively and made tags correspond to the engine's datatype and implemented a parser for each. Not a biggie, since there was a finite amount of possible component types provided by the engine.
Logged

oahda
Level 10
*****



View Profile
« Reply #856 on: October 11, 2016, 12:24:27 PM »

Does anybody compile C++ with optimisations (-O and some number)? I didn't know about the flags until recently, and didn't realise they weren't specific to Emscripten, where I first met them... Possibly embarrassing?

Why do you use them or why do you not? Differences between debug and release? What particular settings and why?
Logged

InfiniteStateMachine
Level 10
*****



View Profile
« Reply #857 on: October 11, 2016, 12:49:10 PM »

Those are major sources of code optimizations. Usually debug builds have none and final builds use O2. IIRC O2 is usually set by default for release builds. At least in the world of MSVC.

Here's the gcc docs on the switches.

https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html


Also another tip, if you want to de-optimize a specific code file you can go #pragma optimize off. Useful for when you want decent symbols for part of a relase build.

Logged

agedev
Level 0
**


View Profile
« Reply #858 on: October 11, 2016, 01:24:29 PM »

Does anybody compile C++ with optimisations (-O and some number)? I didn't know about the flags until recently, and didn't realise they weren't specific to Emscripten, where I first met them... Possibly embarrassing?

Why do you use them or why do you not? Differences between debug and release? What particular settings and why?

Well, not just anybody but everybody. The only time one generally doesn't use the optimisation flag is for debug builds or in rare cases of compiler optimisation issues. No need to be embarrassed though. It would be only be surprising for you to be unaware of it if you spent a lot of time hand writing build systems. The reason being just about every IDE will set it by default on builds for you.
Logged
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #859 on: October 11, 2016, 06:09:37 PM »

I have come back to a bit of programming to do some mesh stuff, but I'm having a weird stuff not sure If I'm dumb:

Code:
using UnityEngine;
using System.Collections;

public class mesh2Hedges : MonoBehaviour {

public Mesh UnityMesh;
public GameObject GO;

triangle[] trianglelist;


private class triangle
{
public int index1 = 0,index2 = 0, index3 = 0;
public Vector3 pos1, pos2, pos3, barycentre;


}

void CreateTriangleFromMesh(Mesh m)
{
int[] meshtri;
Vector3[] v;
triangle[] tri;

tri = new triangle[m.triangles.Length/3];

meshtri = m.triangles;
v = m.vertices;


print(m);
print(tri.Length);
print(v.Length);
print(meshtri.Length);

if (m == null)
{
print("xxx m");
return;
}
if (tri == null)
{
print("xxx tri");
return;
}
if (meshtri == null)
{
print("xxx meshtri");
return;
}
if (v == null)
{
print("xxx v");
return;
}

int i = 0;
while (i < tri.Length)
{
int x = i*3;
//print (i);
//print (x);

//print(meshtri[x]);
//print(meshtri[x+1]);
//print(meshtri[x+2]);
//print("...............");

print(tri[i].index1);
print(tri[i].index2);
print(tri[i].index3);

//tri[i].index1 = meshtri[x];
//tri[i].index2 = meshtri[x+1];
//tri[i].index3 = meshtri[x+2];

//tri[i].pos1 = v[tri[i].index1];
//tri[i].pos2 = v[tri[i].index2];
//tri[i].pos3 = v[tri[i].index3];

i++;
}

trianglelist = tri;

}




// Use this for initialization
void Start ()
{
GO = this.gameObject;
UnityMesh = this.GO.GetComponent<MeshFilter>().mesh;

if (UnityMesh != null) CreateTriangleFromMesh(UnityMesh);
if (UnityMesh == null)print("xx");
}

// Update is called once per frame
void Update ()
    {

}
}

I'm getting
NullReferenceException: Object reference not set to an instance of an object
mesh2Hedges.CreateTriangleFromMesh (UnityEngine.Mesh m) (at Assets/mesh2Hedges.cs:95)
mesh2Hedges.Start () (at Assets/mesh2Hedges.cs:164)

 Huh?

I can't initialize a int?

-> I can store the meshindex from meshtri to tri.index
-> I can't print tri.index anyway
Logged

Pages: 1 ... 41 42 [43] 44 45 ... 69
Print
Jump to:  

Theme orange-lt created by panic