• What do you need help with? V. 3.0
    4,884 replies, posted
[QUOTE=Overv;31734373]Press the insert key.[/QUOTE] Well then, I feel stupid. Never again will I smash the keyboard with both hands in anger.
[QUOTE=q3k;31728808]edit: disregard that, I suck cocks, forgot "unsigned long" is 64-bit in some gcc versions, so I didn't talk with the server correctly.[/QUOTE] longs are the same size as a pointer
[QUOTE=pinkfreud;31734814]longs are the same size as a pointer[/QUOTE] [url=https://secure.wikimedia.org/wikipedia/en/wiki/64-bit#Specific_C-language_data_models]Depends on the platform.[/url]
If you include <stdint.h> (or <cstdint> if you use C++), you get two types, intptr_t and uintptr_t. Guaranteed to hold a pointer.
Would it be suitable for me to post a question here regarding something I'm trying to do in MS Excel? (Agree = yes, Disagree = no)
-snip-
[QUOTE=Chrispy_645;31737714]Would it be suitable for me to post a question here regarding something I'm trying to do in MS Excel? (Agree = yes, Disagree = no)[/QUOTE] Why make an irrelevant post asking if you can make a post about something that may be irrelevant? Just make the post, and if it's irrelevant to this thread we'll let you know. [editline]14th August 2011[/editline] [QUOTE=masonrulz;31738018]I'm trying to make a VERY basic converter, and I'm trying to make it convert 1 type to another without having a button. What am I doing wrong? [code]-code snip- [/code] [editline]15th August 2011[/editline] Also, how would I deal with exception handling with something like this? If you couldn't tell, I'm rather new to C#.[/QUOTE] Make sure that those methods are added as event callbacks and not just written in. In the winforms editor, click one of the textboxes then, in the properties panel, click the lightning bolt icon. Scroll down to TextChanged (or something very similar to that) and select the proper method for that textbox. You can also do this manually (not really recommended if you're already using winforms to handle everything for you, but just so you know...) in the constructor with: metersTextBox.TextChanged += metersTextBox_TextChanged;. When you type in the += you can also hit Tab twice and it will write in the rest of the line for you and generate a new method block for the event. Note that if you're going to write a new method for an event, you can just select the TextChanged event in the properties panel and double click it, it'll generate the method block for you instead of you having to write it yourself. And about the exceptions, wrap whatever code that may throw an exception in a try {} block. To catch exceptions from a try block, add a catch {} block. Note that you can also catch certain types of exceptions: try { ... } catch(ArgumentException e) { Console.WriteLine(e.Message); } For the double parsing that you're doing (I'm assuming you want to catch the parsing exceptions), you can also use double.TryParse. It won't throw an exception, just return false if it can't parse. So you wrap that method in an if statement. The last parameter needs to be written as "out myDouble" instead of just "myDouble"
What's a good alternative to a singleton for something like an object manager? [cpp]#include <map> #include "Object.h" #define OBJMGR ObjectManager::Instance() class ObjectManager { std::map<unsigned int, Object*> Objects; unsigned int NextID; ObjectManager(); public: static ObjectManager* Instance(); void CreateBlock(const Vector3& pPosition); void CreateBot(const Vector3& pPosition); };[/cpp] Also, it's become a bit of a habit for me to use 'const Vector3&' instead of just 'Vector3'. I'm confused why more people don't do it this way. Is there anything wrong with it?
[QUOTE=jalb;31738617]Also, it's become a bit of a habit for me to use 'const Vector3&' instead of just 'Vector3'. I'm confused why more people don't do it this way. Is there anything wrong with it?[/QUOTE] Never thought of that actually. I suppose you could make an instance of it and then pass that instance to every method/object needing it.
[QUOTE=thf;31738833]I suppose you could make an instance of it and then pass that instance to every method/object needing it.[/QUOTE] I've considered this, but that seems to create even more of a dependency than the singleton would. Are there any other inputs on this? All my research on singletons just seems to suggest that they're overused. They're good for some things, but most of the time they're not ideal. Wasn't sure if I was missing some obvious alternative.
It does make it much more modular.
KISS. Use a singleton.
[QUOTE=Jookia;31739338]KISS. Use a singleton.[/QUOTE] I've used singletons many times in the past. This is probably the 15th object manager I've written. All of them were singletons. My professors have warned me how controversial they can be so I was looking around for alternatives. I'll probably use one internal singleton, "GameWorld." It will contain all the classes I would otherwise make a singleton, such as object manager, or messager.
Okay I'll post this now. Right now in Excel I'm simulating video game sales. - From Jan 2012 to Feb 2015, video game sales start at 100 copies, then increases at 10% per month. So 100 copies sold, then 110 copies, then 121, etc. - At March 2015, video game sales suddenly drops to 100. It doesn't matter how many sales were before it, it drops to 100. From April 2015 to December 2020, video games sales decreases at 10%. So from 100 copies sold, to 90 copies sold, to 81 copies, etc. Is there any way I can easily change when the sales increase at 10%, when the sales drops to 100 copies sold, and when the sales decrease at 10%? Right now I'm using IF statements for this. I made a column which has 3 values - either 0, 1, or -1. 0 means that sales increase at 10%, 1 means that sales drop to 100, and -1 means that sales decrease at 10%. Is there a much better way to go about this? Here's what I mean (was trying to write with the mouse =/ ): [img]http://dl.dropbox.com/u/12453703/sales.png[/img] I have uploaded my spreadsheet here: [url]http://dl.dropbox.com/u/12453703/gaem.xlsx[/url] Cheers :smile:
[QUOTE=jalb;31738617]Also, it's become a bit of a habit for me to use 'const Vector3&' instead of just 'Vector3'. I'm confused why more people don't do it this way. Is there anything wrong with it?[/QUOTE] Nothing wrong with it. Const reference is the usual way to pass objects to functions, because it provides the same level of protection as passing a copy (i.e. the callee can't modify the caller's object) without the overhead of actually making a copy.
[QUOTE=Chrispy_645;31739801]-words-[/QUOTE] I don't see why you wouldn't just put in different rules for Jan-12 to Feb-15, Mar-15, and Apr-15+. Start Jan-12 at 100, make all of them to Feb-15 be the number from the previous month plus the 10%. Change Mar-15 to 100, then do the same thing with -10%. Maybe I'm just lazy. [QUOTE=Wyzard;31739816]Nothing wrong with it. Const reference is the usual way to pass objects to functions, because it provides the same level of protection as passing a copy (i.e. the callee can't modify the caller's object) without the overhead of actually making a copy.[/QUOTE] Right. I guess people just can't be arsed to type const class& every time. V:v:V
I know what you mean, and I did exactly what you've said prior to adding if statements, but I want to try and make it so that you can change when the sales drops to 100 as easily as possible, rather than modifying formulas. I don't mind changing the formulas manually, but when I do my exam, whoever's marking my exam will want to see if I've made it easy for others to change when sales drop to 100. By "easy" it could mean maybe, having a dropdown list and selecting what month the sales should drop to 100, and the Excel will take care of the 10% increase and 10% decrease. I don't know if that's easily possible... which is why I'm asking you guys. :smile:
[QUOTE=jalb;31738617]What's a good alternative to a singleton for something like an object manager? #include <map>#include "Object.h"#define OBJMGR ObjectManager::Instance()class ObjectManager{ std::map<unsigned int, Object*> Objects; unsigned int NextID; ObjectManager();public: static ObjectManager* Instance(); void CreateBlock(const Vector3& pPosition); void CreateBot(const Vector3& pPosition);}; Also, it's become a bit of a habit for me to use 'const Vector3&' instead of just 'Vector3'. I'm confused why more people don't do it this way. Is there anything wrong with it?[/QUOTE] Make an object called Game or something, which creates its managers in its constructor. [editline]15th August 2011[/editline] [QUOTE=jalb;31739793]I'll probably use one internal singleton, "GameWorld." It will contain all the classes I would otherwise make a singleton, such as object manager, or messager.[/QUOTE] Oh, overread that D:
[QUOTE=Wyzard;31739816]Nothing wrong with it. Const reference is the usual way to pass objects to functions, because it provides the same level of protection as passing a copy (i.e. the callee can't modify the caller's object) without the overhead of actually making a copy.[/QUOTE] Carrying on from this post; If you wanna know more about these sorts of simple/useful optimisations and so on, I highly recommend reading [url=http://www.amazon.co.uk/Effective-Specific-Addison-Wesley-Professional-Computing/dp/0321334876]Effective C++[/url]. It's a really good read and can teach you a lot.
anyone know any good articles on networking, common practices or something? specifically, I want to send packets between my programs with data. These could be different types of data, so I would need a way to differentiate between types of data, and I don't know what the most common way of doing this is...
[code]invalid conversion from 'LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM)' to 'LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM)'[/code] wat One's a static method, but shouldn't it work?
[QUOTE=Jimbomcb;31742812]anyone know any good articles on networking, common practices or something? specifically, I want to send packets between my programs with data. These could be different types of data, so I would need a way to differentiate between types of data, and I don't know what the most common way of doing this is...[/QUOTE] Check out [url=http://code.google.com/p/protobuf/]protobufs[/url], write your own binary blob format (made of (type, data) tuples), use something like JSON, or just have a bunch of different packet types, each one identified by a integer at the beggining.
Does anyone know an elegant way of using Lua scripts in a C++ program, not in a separate lua file, but instead integrated into the exe file of the program and then loaded into the Lua parser somehow?
[QUOTE=thf;31743412]Does anyone know an elegant way of using Lua scripts in a C++ program, not in a separate lua file, but instead integrated into the exe file of the program and then loaded into the Lua parser somehow?[/QUOTE] On Windows you can include so-called resources in your executable (usually icons, bitmaps, ...), and then use them with [url=http://msdn.microsoft.com/en-us/library/ms648042(v=vs.85).aspx]FindResource[/url], [url=http://msdn.microsoft.com/en-us/library/ms648046(v=vs.85).aspx]LoadResource[/url] and [url=http://msdn.microsoft.com/en-us/library/ms648047(v=vs.85).aspx]LockResource[/url].
[QUOTE=Jimbomcb;31742812]anyone know any good articles on networking, common practices or something? specifically, I want to send packets between my programs with data. These could be different types of data, so I would need a way to differentiate between types of data, and I don't know what the most common way of doing this is...[/QUOTE] Networking is very application-specific. The networking structure of an online game is very different than, say, a media streaming application. Some applications absolutely need information to arrive complete and in-order regardless of how long it takes. Some programs need to send a lot of information about things that aren't necessarily ordered in any particular way. Others have real-time demands where information is basically useless if it doesn't arrive in a timely manner. You have to decide what your priorities are before you decide on the structure of your networking system. As for determining what type of information is stored in a packet, store an enum/integer representing message type before each chunk of data.
[QUOTE=q3k;31743488]On Windows you can include so-called resources in your executable (usually icons, bitmaps, ...), and then use them with [url=http://msdn.microsoft.com/en-us/library/ms648042(v=vs.85).aspx]FindResource[/url], [url=http://msdn.microsoft.com/en-us/library/ms648046(v=vs.85).aspx]LoadResource[/url] and [url=http://msdn.microsoft.com/en-us/library/ms648047(v=vs.85).aspx]LockResource[/url].[/QUOTE] But is there a portable way of doing it, or maybe a more elegant way of using lua in your game without exposing the raw source code?
[QUOTE=thf;31743515]But is there a portable way of doing it, or maybe a more elegant way of using lua in your game without exposing the raw source code?[/QUOTE] The only portable way to do it is using Qt's resources, but Qt is huge. You could also write separate code for Linux (elf files also have something akin to resources, IIRC) and OS X (just read stuff from the .app bundle). If you don't want to store source code, you can store [url=http://www.lua.org/manual/4.0/luac.html]precompiled Lua code[/url].
[QUOTE=q3k;31743226]Check out [url=http://code.google.com/p/protobuf/]protobufs[/url], write your own binary blob format (made of (type, data) tuples), use something like JSON, or just have a bunch of different packet types, each one identified by a integer at the beggining.[/QUOTE] Was thinking about a byte or integer or something at the start of the packet but wasn't sure if it was a bad thing to do for reasons beyond me. [QUOTE=ROBO_DONUT;31743509]Networking is very application-specific. The networking structure of an online game is very different than, say, a media streaming application. Some applications absolutely need information to arrive complete and in-order regardless of how long it takes. Some programs need to send a lot of information about things that aren't necessarily ordered in any particular way. Others have real-time demands where information is basically useless if it doesn't arrive in a timely manner. You have to decide what your priorities are before you decide on the structure of your networking system.[/QUOTE] Cheers, am aware of the differences between networking for different applications etc, have already settled on the structure of the networking, just not sure about this one part [QUOTE=ROBO_DONUT;31743509]As for determining what type of information is stored in a packet, store an enum/integer representing message type before each chunk of data.[/QUOTE] thanks
Wait, I can't use resource files in Visual C++ Express, can I?
[QUOTE=thf;31743515]But is there a portable way of doing it, or maybe a more elegant way of using lua in your game without exposing the raw source code?[/QUOTE] You can execute strings as Lua with luaL_dostring.
Sorry, you need to Log In to post a reply to this thread.