Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411430 Posts in 69363 Topics- by 58416 Members - Latest Member: JamesAGreen

April 19, 2024, 07:11:11 PM

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



View Profile
« Reply #820 on: August 08, 2016, 01:26:22 AM »

Yeah, it's great to spitball a bit, and it's a good thing to stay away from creator's pride. Tongue

Completely unrelated question: no STL function or std::string member to trim strings yet? In C++14? What? Please tell me it's there and I just can't find it?
Logged

JWki
Level 4
****


View Profile
« Reply #821 on: August 08, 2016, 01:30:36 AM »

Nah they expect you to use find_first_not_of and find_last_not_of to get the string bounds and then substring on those to get the trimmed string.
Logged
oahda
Level 10
*****



View Profile
« Reply #822 on: August 08, 2016, 02:00:00 AM »

Geez.
Logged

Kylotan
Level 0
**


View Profile WWW
« Reply #823 on: August 08, 2016, 05:35:24 AM »

I think it's at the point now where C++ std::strings are worthless for most of the originally intended uses because they're not Unicode aware in any meaningful way. Unfortunately the state of Unicode in C++ is a mess too...
Logged
oahda
Level 10
*****



View Profile
« Reply #824 on: August 08, 2016, 05:53:58 AM »

Actually these days with C++11 and C++14 Unicode works just fine with std::strings if prefixed with u8. And beyond that, there's also std::u16string and std::u32string these days. I've had great success unicoding with those (working on a localisation library). Can even write those strings right into the code files if they have the correct encoding.
« Last Edit: August 08, 2016, 06:00:30 AM by Prinsessa » Logged

Kylotan
Level 0
**


View Profile WWW
« Reply #825 on: August 08, 2016, 06:39:16 AM »

Hmm, my understanding is that u8 will translate your literals for you, but won't fix the fact that std::string itself has no idea how to handle Unicode and therefore many of its member functions could easily break the text inside it or return false positives from find operations.
Logged
oahda
Level 10
*****



View Profile
« Reply #826 on: August 08, 2016, 06:45:09 AM »

Ah, right. Yeah, that's possible. Heard the regex stuff isn't working well either.

I actually concatenate strings and stuff for my character type agnostic localisation system (it uses std::basic_string<T> with the type defined by the user) as tho they were vectors, because string streams don't work properly with the new types char16_t and char32_t either. Forgot about that. :/

Still messy, but not as hopeless as before. At least the new types in and of themselves play nicely, even if the STL functionality isn't there, so it's not too difficult to write a couple of custom functions. Way better than before at least...
Logged

oahda
Level 10
*****



View Profile
« Reply #827 on: August 10, 2016, 11:56:07 AM »

Wait, should I basically be marking every single function with noexcept in modern C++..?
Logged

Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW
« Reply #828 on: August 10, 2016, 03:08:32 PM »

Wait, should I basically be marking every single function with noexcept in modern C++..?

I reserve noexcept for functions that are never supposed to throw under any circumstances, primarily destructors and move operations.  Other than those, I would only use it for extremely simple functions that I know would never throw, usually small inline functions.

Anything that allocates memory could throw a std::bad_alloc exception, so you can't use it too generally.
Logged



What would John Carmack do?
Kylotan
Level 0
**


View Profile WWW
« Reply #829 on: August 12, 2016, 03:08:44 AM »

I can't remember the last time I worked on a C++ project where exceptions were even enabled.

If you ever get into a situation where you hit a std::bad_alloc then you're screwed anyway.
Logged
Oats
Level 1
*


High starch content.


View Profile
« Reply #830 on: August 28, 2016, 11:17:31 PM »

Hiya, I'm trying my best but my math really isn't up to scratch on this one, how do I find the circumsphere of an irregular tetrahedron?  I have for four vectors A, B, C and D that describe a tetrahedron, I need to know the circumsphere's radius and and centre. I know that it can be found by taking any three of the edges, finding the plane perpendicular to the edge and which passes through the edges midpoint, then the circumcentre is the point where those three planes intersect, but this is where I'm struggling. I'm doing this for Delauney triangulation, any help would be appreciated!

Oh wait I found an answer myself, way easier: http://www.gdmc.nl/publications/2007/Computing_3D_Voronoi_Diagram.pdf
« Last Edit: August 29, 2016, 03:59:30 AM by Oats » Logged

eh
Alessio
Level 0
***


Visual Artist


View Profile
« Reply #831 on: September 06, 2016, 11:26:37 AM »

Quick question. I'm using GM:Studio as base but i believe it may apply to anything.

I have this code:
Code:
var i, string_text
if instance_exist(obj_thing)
string_text[0] =  string("hello")
else
string_text[0] =  string("world")
Plus a for loop:
Code:
for(i=0; 1<4; i++) draw_text(16, 32+(16*i), string_text[i])

At compile, i get error:

Code:
Push :: Execution Error - Variable Index [0,1] out of range [1,1] - -7.string_text(100003,1)

You can't just change a value stored into an array at will, right? I know that programming permits a lot of things but i'm not sure about this one.

Alternatively, i can make this as a workaround, right?
Code:
string_text[0] =  string(customText)
if instance_exist(obj_thing)
customText =  string("hello")
else
customText =  string("world")

I wanna note these are pseudocodes, anyway.
Logged
Sakar
Guest
« Reply #832 on: September 06, 2016, 01:59:33 PM »

In Game Maker you are able to change the value in an array at will.

The main issue is that var defines a local variable, so if you declare string_text in the Create event, it will be inaccessible outside of that event. Your code changes to this:
Code:
if instance_exist(obj_thing)
   string_text[0] =  string("hello")
else
   string_text[0] =  string("world")

Simple assigning to string_text[0] creates a variable on the object which can be accessed in any of its events.

Also your for loop should be

for(i=0; i<4; i++)

(that will crash if you have fewer than 4 elements in the string_text array, tho)
Logged
DragonDePlatino
Level 1
*



View Profile WWW
« Reply #833 on: September 20, 2016, 02:22:59 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?
Logged

InfiniteStateMachine
Level 10
*****



View Profile
« Reply #834 on: September 20, 2016, 04:46:34 PM »

I tend to use C for personal projects more often than C++. I find it really nice and it compiles relatively quickly.  SDL is pretty well established too. More importantly I would suspect you would have less platform issues using C.

Why are you sick of C++? That might help answer the question.
Logged

DragonDePlatino
Level 1
*



View Profile WWW
« Reply #835 on: September 20, 2016, 06:56:39 PM »

SDL2? I've used that in the past with C++ so I'll give it a shot! Do you know any good C tutorials for SDL2? I can only seem to find C++ SDL2 tutorials. Sad

I'd rather not go into detail why I dislike C++. I have a lot to say but I don't want to start an argument.
Logged

ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #836 on: September 20, 2016, 07:32:48 PM »

Simply explaining why you dislike it shouldn't start an argument, it's basically just explaining your experience with the language.
Logged

oahda
Level 10
*****



View Profile
« Reply #837 on: September 21, 2016, 12:34:39 AM »

We're hopefully mature enough here to realise there are different preferences and that language wars, like console wars, are a bit ridiculous. c;

If you explain what you dislike about C++, and probably also what you don't dislike about it, it'll be easier to find something that suits you better. Hand Thumbs Up Right

Relevant question, tho: are you using C++98 or modern C++? They're rather different from each other. If it's C++98 you dislike, perhaps modern C++ deals with a lot of your issues.
Logged

InfiniteStateMachine
Level 10
*****



View Profile
« Reply #838 on: September 21, 2016, 04:45:30 AM »

SDL2? I've used that in the past with C++ so I'll give it a shot! Do you know any good C tutorials for SDL2? I can only seem to find C++ SDL2 tutorials. Sad

I'd rather not go into detail why I dislike C++. I have a lot to say but I don't want to start an argument.

SDL2 is a C++ api now? That's news to me.



The reason I asked about what you dislike about C++ is the following: If the reason was the rather large/complicated standard library I'd say C because Java's standard library is pretty vast. It the reason was because you don't like memory management then I would say Java because it does most of that work for you with its GC.
Logged

DragonDePlatino
Level 1
*



View Profile WWW
« Reply #839 on: September 21, 2016, 04:46:15 AM »

*Deep breath*

When I use a tool, I like to fully understand how to use it. I used to use photoshop, but I switched to pixel art programs. I used to use word processors, now I use notepad. If I'm weighed down by lots of features I'll never use, it distracts me from working.

And that's the primary issue I have with C++. Over the weekend, I programmed my own Entity Component System modelled after EntityX. I learned about namespaces, templates, variadic functions, friend classes and static casting. I fully understood all of this and finished my ECS, but I felt frustrated by the number of obscure quirks I had to learn. I can store an array of templated objects in an array, but first I need to create an empty parent object and fill the array with that. Then I static_cast the parent object to the templated child object and use that pointer to access the data in the component array and ARRRRGH!

And yes, before anyone says anything, I know I can use [obscure feature] or [programming paradigm] or [game programming pattern] to fix my problem. Which brings me to my next point...paradigms in C++. So many options! Procedural, object-oriented, generic, metaprogramming, data-driven...but can anyone agree on them? Nope! In every StackOverflow post you find, you have 5 different people arguing the best and correct way to do something in C++. For someone learning the language, it's overwhelming. You have people writing C-style code, plain C++, modern C++11, boost C++...the language tries to accomodate everything and the kitchen sink and is a massive mess as a result. On StackOverflow, I've seen people who have professionally programmed for in C++ for 20+ years and are frequently surprised at the new features they find.

C++ has a complex 33 year history behind it spanning multiple standards and maintainers. Every addition adds new features like iterators, lambda expressions and type deduction, but depreciated features like va_list are kept in the language. Learning anything in C++ requires prying back decades of development and understanding the history of the ISO standard. As an example: take template definitions. In tutorials, people use both <class T> and <typename T>, often interchangeably. For someone learning about templates, that's really confusing! So I looked it up and found this. Basically, over a decade ago some committee decided that <typename T> would clear up the confusion of future programmers. In reality, it accomplished the exact opposite.

And its for that reason I want to switch languages after months of dedicating myself to C++. As time went on, things became less about making a game and more about learning the quirks of the language. I wanted to focus on making a game, but not see the sacrifice of speed or control that comes with engines like Game Maker. And ultimately, I guess C++ isn't the tool for me.

In contrast, both Java and C are easier languages to learn and fully understand. From what I understand, Java is aggressively object-oriented so you don't have to pick from a dozen different progamming paradigms. C is very bare-bones, but lightning-fast and possible for mere mortals to fully understand. I know things overall will be more difficult in C (less syntax but more memory management) but I at least want to give it a shot.

In the end, I'll probably end up crawling back to the monstrous mess that is C++. But at least I'll have tried something different! And who knows? Next time, maybe I'll stick to the basic C++ features and ignore the dozens of options modern C++ provides.
Logged

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

Theme orange-lt created by panic