deepdene

Members
  • Content count

    252
  • Joined

  • Last visited

Community Reputation

292 Neutral

About deepdene

  • Rank
    Member
  1. Private vs public

    One thing worth mentioning is the whole data orientated programming movement thats very popular amongst commercial developers. Mike Acton from Insomniac Games is one of the main components. Basically it relies on very clear data sets of your data, then using more the encapsulations of Managers which manage that data. So for example character AI data would be all sequential blocked together where you'd use it, and rather than encapsulating a Update method on a AICharacter object, you'd instead have AIManager which would access like data at once. In this paradigm the data would be exposed potentially through the old C struct style declarations where everything is public because your not so much interested in the traditional object abstraction, your more interested in the data. Classes/Objects and data orientated design aren't mutually exclusively, they can co-exist but you have a different way of structuring your data/classes etc. Read some more if you like: http://gamesfromwithin.com/data-oriented-design-now-and-in-the-future http://altdevblogaday.com/pages/how-does-it-work http://home.comcast.net/~tom_forsyth/blog.wiki.html#%5B%5BData%20Oriented%20Luddites%5D%5D http://home.comcast.net/~tom_forsyth/blog.wiki.html#%5B%5BMoore's%20Law%20vs%20Duck%20Typing%5D%5D The traditional OO view does have many advantages, mainly in regards to potentially higher gains in maintainability. DoD has definite speed advantages and forcing a clean/simple hierarchy can have some advantages in terms of readability at times, but sometimes OO abstractions are much easier on the human brain. If your starting out in your early projects I'd recommend starting out with OO but keep an open mind its not the only approach.
  2. [quote name='mhagain' timestamp='1296562961' post='4767918'] Using the Windows API without C coding practices is pretty much impossible; at the very least your WndProc will need to be a procedural function. [/quote] static functions inside the class can be used for the WndProc, obviously outside the object instance.
  3. Best XNA book?

    Some friends found this book quite useful http://www.amazon.com/XNA-Game-Studio-4-0-Programming/dp/0672333457/ref=sr_1_3?ie=UTF8&qid=1295685722&sr=8-3 Both by guys on the Microsoft XNA team.
  4. Function pointer cast and vtable, isn't that bad?

    Remember in C everything is treated as Data. So as long as the data matches up things keep working. Which is different to the OO approach where its about discrete sets of data and functionality combined.
  5. tool to convert C++ code to Java

    Another thing to note is that Java does allow you to interface with C++ through the use of JNI interfaces.
  6. C++ general questions

    [quote name='fastcall22' timestamp='1295424846' post='4761129'] [quote name='deepdene' timestamp='1295417522' post='4761091'] +1 on Palidine's opinion. [/quote] They have a button for that now, just so you know! [/quote] There you go button pressed
  7. Undo a dot product

    The dot product of two unit vectors is the cosine of the angle. You can always normalise your vectors. So then you can use the acos to calculate the angle
  8. C++ general questions

    Header files by convention are used to place function and class definitions. The #include <filename> vs #include "filename" is complex by definition but generally in almost all implementations it means: #include "<filename>" will search the current directory (and those defined in the project as additional search locations) for the filename specified. Then it grabs the contents of the file, runs it through the preprocessor and then place the contents directly in the current place in the file. #include <filename> will search the system header directories rather than the project defined ones. Now in reality what it means is the following (copy and paste from: [url="http://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename"]http://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename[/url]) [font=Arial,][size=4]In the C standard (find N1124.PDF), section 6.10.2 paragraphs 2 to 4 state:[/size] [size=4]2) A preprocessing directive of the form[/size] [color=gray][size=4]#include[/size][/color][color=black][size=4] [/size][/color][color=black][size=4]<[/size][/color][color=black][size=4]h[/size][/color][color=black][size=4]-[/size][/color][color=#00008B][size=4]char[/size][/color][color=black][size=4]-[/size][/color][color=black][size=4]sequence[/size][/color][color=black][size=4]>[/size][/color][color=black][size=4] [/size][/color][color=#00008B][size=4]new[/size][/color][color=black][size=4]-[/size][/color][color=black][size=4]line [/size][/color][size=4]searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the < and > delimiters, and causes the replacement of that directive by the entire contents of the header. How the places are specified or the header identified is implementation-defined.[/size] [size=4]3) A preprocessing directive of the form[/size] [color=gray][size=4]# include "q-char-sequence" new-line[/size][/color][color=black][size=4] [/size][/color][size=4]causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read[/size] [color=gray][size=4]# include <h-char-sequence> new-line[/size][/color][color=black][size=4] [/size][/color][size=4]with the identical contained sequence (including > characters, if any) from the original directive.[/size] [size=4]4) A preprocessing directive of the form[/size] [color=gray][size=4]# include pp-tokens new-line[/size][/color][color=black][size=4] [/size][/color][size=4](that does not match one of the two previous forms) is permitted. The preprocessing tokens after include in the directive are processed just as in normal text. (Each identifier currently defined as a macro name is replaced by its replacement list of preprocessing tokens.) The directive resulting after all replacements shall match one of the two previous forms.145) The method by which a sequence of preprocessing tokens between a < and a > preprocessing token pair or a pair of " characters is combined into a single header name preprocessing token is implementation-defined.[/size] [size=4]h-char: any member of the source character set except the new-line character and >[/size] [size=4]q-char: any member of the source character set except the new-line character and "[/size] [/font]
  9. C++ general questions

    [quote name='Palidine' timestamp='1295402360' post='4761001'] Dec-c++ is over 10 years old and terrible. Visual Studio is pretty much the industry standard and a really awesome IDE. You can get it free, just google "Visual Studio Express Edition" [/quote] If you are a student you can also get Visual Studio 2010 Pro for free at www.dreamspark.com +1 on Palidine's opinion.
  10. Connect 4 C++

    Hi there, First thing, I personally find it hard to read an entire two chunk of code like that. i.e. it's better if you ask more tailored questions about a small task you are doing. The reason why his always return 3, is because if you look inside the function aiTurn() it returns 3. You can generate random numbers in C++ by using the rand() function accompanied with srand(). So you'd do something along the lines of [code] #include <cstdlib> #include <ctime> #include <iostream> int main() { // This is a unique value that is passed to the random number generator. // Must be only called once. srand(time(NULL)); // Gives a number between 0..99 int random = rand() % 100; std::cout << random << std::endl; // Gives a number between 0..999 random = rand() % 1000; std::cout << random << std::endl; return 0; } [/code]
  11. Difference between C# OVER C++?

    From a more general point of view that isn't a language specific difference, Visual Studio provides alot of tools for doing GUI editing, database hookups etc. So you can create forms in WPF/Winforms which are GUI frameworks, can create entity framework hookups which is a object relational tool etc, plus many other tools I can't think of. C++/CLI has some of these tools but its not as tightly fitted. C++/CLI being a standard produced from Microsoft to make some additions to C++ to provide better syntax for integration into a managed environment. The .NET framework is massive, it takes the kitchen sink approach while in C++ the standards committee took the approach a 3rd party would provide additional functionality outside a core set of functionality. Also from a language point of view, there have been many extensions lately towards being a hybrid functional/procedural language with frameworks like Linq being added, lamda functions etc. Functional language features making it possible to add some constructs to potentially make it easier to scale certain things. i.e. they added the parallel tasks library and parallel linq to provide features such as iterating over large datasets concurrently using a lambda function etc.
  12. which is fastest way to inverse a number in c++?

    [quote name='Hodgman' timestamp='1295313924' post='4760482'] [quote name='V-man' timestamp='1295295752' post='4760319'] [quote name='Antheus' timestamp='1295294888' post='4760307'] This [url="http://thedailywtf.com/Articles/Classic-WTF-The-Challenges-of-Negation.aspx"]article[/url] outlines several other methods. [/quote]Yes but that article, that function sets up some other variables and thus it is slower. The fastest way to batch process is to use MMX for integers and SSE for floats using the CPU. The GPU way would be way faster. Use CUDA or OpenCL.[/quote]No it should be done in the cloud with HTML and variables. [/quote] If you believe the buzz you could almost believe that.
  13. pointers question

    [quote name='nuclear123' timestamp='1295233374' post='4759907'] Test::Test(int id, double *ptr) { id = ptr; // what does this do? id = *ptr; // what does this statement do as well? } -thx im a bit confused on pointers and trying to understand this [/quote] id = ptr sets the id to be the memory address to which the pointer to ptr points towards. So its the address the computer uses internally id = *ptr; the pointer will be dereferenced and will then get access to the contents in memory. So most likely the double value your interested in. Then it will most likely be a truncated double value since id is an int. You may for safety consider using a reference, a reference gets rid of the need of dereferencing the variable while passing around memory addresses.
  14. [quote name='m_switch' timestamp='1295206621' post='4759746'] Note that the semantics of properties and public variables that return value types are different. For public variables, you are directly accessing the variable. However, a property that returns a value type makes a copy of the variable. [/quote] [font="arial, verdana, tahoma, sans-serif"][size="2"]In both instances with value types the values are placed onto the evaluation stack and popped into the appropriate stack variable. Our class definition and code we are basing this MSIL off:[/size][/font][font="arial, verdana, tahoma, sans-serif"][size="2"] [code] using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class A { public int x; public int X { get { return this.x; } set { this.x = value; } } public int J { get; set; } } class Program { static void Main(string[] args) { A a = new A(); a.x = 22; int x = a.x; a.X = 32; x = a.X; int j = 0; a.J = 22; j = a.J; } } } [/code] Here's the difference in MSIL between accessing the property and the field. [/size][/font] [code] . maxstack 2 .locals init ( [0] class ConsoleApplication1.A a, [1] int32 x, [2] int32 j ) // Load the class onto the evaluation stack L_000f: ldloc.0 // Load the value from the field onto the evaluation stack L_0010: ldfld int32 ConsoleApplication1.A::x // Pop the value from the evaluation stack into the local stack variable 1L_0015: stloc.1 // Now property example // Load the class onto the evaluation stack L_001f: ldloc.0 // Call a late bound method on the object on the top of the evaluation stack pushing the return value onto the evaluation stack L_0020: callvirt instance ConsoleApplication1.A::get_X() // Pop the value from the evaluation stack into the local stack variable L_0025: stloc.1 [/code] Also the only difference between a automatic property and providing the backing field yourself in terms of MSIL is the fact that the compiler adds an attribute to the field I believe to indicate it's compiler generated.
  15. BTW automatic properties are the equivalent to the following just to clarify those who haven't seen this newer language feature. [code] class A { private int x; public int X { get { return this.x; } set { this.x = value; } } } [/code] is equivalent to : [code] class A { public int X { get; set; } } [/code]