• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

DevFred

Members
  • Content count

    2418
  • Joined

  • Last visited

Community Reputation

840 Good

About DevFred

  • Rank
    Contributor
  1. Just for completeness, here is an O(n) recursive solution: int fib(int n, int a, int b) { return (n <= 0) ? a : fib(n - 1, b, a + b); } int fib(int n) { return fib(n, 0, 1); } It is possible to convert the recursive solution into an iterative one: int fib(int n) { int a = 0; int b = 1; while (n --> 0) { int s = a + b; a = b; b = s; } return a; } But I find the recursive solution aesthetically more pleasing :)
  2. SSE has built-in instructions for determining the minimum and maximum, which allows you to get rid of jumps entirely: #include <x86intrin.h> // returns the minimum in *pa and the maximum in *pb void minmax(int* pa, int* pb, int* pc) { __m128 a = _mm_cvtsi32_ss(a, *pa); __m128 b = _mm_cvtsi32_ss(b, *pb); __m128 c = _mm_cvtsi32_ss(c, *pc); __m128 minimum = _mm_min_ss(_mm_min_ss(a, b), c); __m128 maximum = _mm_max_ss(_mm_max_ss(a, b), c); *pa = _mm_cvttss_si32(minimum); *pb = _mm_cvttss_si32(maximum); } Note that due to the conversion from int to float, only numbers up to 16777216 will be treated correctly.   If your processor supports SSE4, which is roughly six years old, you can use the full int range: void minmax(int* pa, int* pb, int* pc) { __m128i a = _mm_cvtsi32_si128(*pa); __m128i b = _mm_cvtsi32_si128(*pb); __m128i c = _mm_cvtsi32_si128(*pc); __m128i minimum = _mm_min_epi32(_mm_min_epi32(a, b), c); __m128i maximum = _mm_max_epi32(_mm_max_epi32(a, b), c); *pa = _mm_cvtsi128_si32(minimum); *pb = _mm_cvtsi128_si32(maximum); } On g++, you need to use -msse4 to enable SSE4.
  3. That won't help at all, because auto mi=0; means int i=0; because 0 is of type int.
  4. If you want to round an int down to a multiple of 64, you can use bitmasking:   x = x & ~63;   Note that this only works for powers of two.
  5. [quote name='3333360' timestamp='1339221313' post='4947577'] However it uses memory to declare this variable, and it works like any other variable (if somewhere in your program there's a reference to this const variable, the program will fetch it's value from memory. [/quote] The constant will only be placed into memory if you take its address or pass it by reference. For example: [code] #include <stdio.h> const int answer = 42; int main() { printf("%d\n", answer); } [/code] turns into: [code] .file "floating.c" .section .rodata.str1.1,"aMS",@progbits,1 .LC0: .string "%d\n" .text .globl main .type main, @function main: .LFB31: .cfi_startproc subq $8, %rsp .cfi_def_cfa_offset 16 movl $42, %edx movl $.LC0, %esi movl $1, %edi movl $0, %eax call __printf_chk movl $0, %eax addq $8, %rsp .cfi_def_cfa_offset 8 ret .cfi_endproc .LFE31: .size main, .-main .ident "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3" .section .note.GNU-stack,"",@progbits [/code] Note how the constant is placed directly into the code, and the variable answer got optimized away.
  6. [quote name='Red Ant' timestamp='1324419662' post='4895906'] I'm aware of that, but I've made a habit of doing it just because it makes it impossible to write silly stuff like is_NaN( 6.3433 ) = false; [/quote] That assignment is always impossible, no matter if you return a bool or a const bool. Again, the const is simply ignored here, it doesn't make any difference whatsoever. The language simply does not allow assigning to scalar rvalues.
  7. [quote name='freeworld' timestamp='1323125323' post='4890877'] why not just switch to a language like C# then? Seems like a lot of work just to do something that is already common place in another almost identical language. [/quote] In what universe is C# "almost identical" to C++?
  8. Since you're using Actor as a polymorphic base class, it needs a virtual destructor. Deleting an Asteroid object through an Actor pointer without a virtual destructor yields undefined behavior.
  9. [quote name='Hannesnisula' timestamp='1313501761' post='4849837'] I'm kind of curious about what's not straight forward, mind giving me some examples? [/quote] 1. What's difference between these two lines? [code] Foo* p = new Foo; Foo* q = new Foo(); [/code] 2. What's the difference between these five lines? [code] Foo a; Foo b(); Foo c = Foo(); Foo d(Foo()); Foo e((Foo())); [/code] 3. Why does the following popular include guard naming pattern invoke undefined behavior? [code] #ifndef __MY_HEADER_GUARD__ #define __MY_HEADER_GUARD__ // ... #endif [/code] 4. In the following example, why is the first swap well-defined, but the second swap isn't? [code] namespace std { template<> void swap(Foo& a, Foo& n); template<typename T> void swap(Bar<T>& a, Bar<T>& b); } [/code] 5. Why can I pass an lvalue to foo, but not to bar? [code] template<typename T> void foo(T&& x); void bar(Bar&& x); [/code]
  10. [quote name='tom_mai78101' timestamp='1304050013' post='4804279'] My preferred languages are C/C++ and Java. Since they both use classes [/quote] There is no language called "C/C++", and C certainly does not have classes.
  11. [quote name='taz0010' timestamp='1295515720' post='4761748'] Only static multidimensional arrays are supported. [/quote] That is a common misbelief. Here is how you allocate a 3D array dynamically: [code] int (*p)[8][9] = new int[7][8][9]; p[0][0][0] = 42; // ... delete[] p; [/code] See my [url="http://stackoverflow.com/questions/4810664/"]FAQ on using arrays in C++[/url]
  12. 1 / 2^(OCTAVES - i) This does not do what you think it does. ^ is the bitwise exclusive-or operator. It has nothing to do with exponentiation, what you appear to want. In that case: 1.0 / (1<<(OCTAVES - i))
  13. In the olden days, processors were slow, and memory was (comparatively) fast. Nowadays, memory is the bottleneck, so lookup tables simply are not a good idea anymore. In fact, memory is so hideously slow these days we need several layers of caches. If you buy a $100 processor, $99 are spent on the clever cache parts, and only $1 on the actual computing part. Herb Sutter's video Machine Architecture: Things Your Programming Language Never Told You has all the details.
  14. Quote:Original post by Evil Steve Write down 1 divided by 3 exactly, as a single real number. That's easy in ternary: 0.1