I've been working on 2 projects for learning.
I never really used C# at all, except for very short projects. But even then, it was just a simple win form. So I've decided to get some experience with it and make a simple game.
[media]
[img]http://i51.tinypic.com/sqtvsk.jpg[/img] <- Main Menu
[/media]
The normal game mode isn't done yet, mainly because of my second project I'm going to tell you about soon. But it's just 4 paddles controlled by a mouse and you have to keep the ball in game.
I'm working on an online game mode for this to where multiple people help to balance the ball in like a co-op fashion. That way I can also get experience with the networking part of the .net library.
But, the other half of my productivity time is going towards using / learning Irrlicht. I never done 3D before and I heard the irrlicht is pretty easy to work with. And it is!
It's very fun and seems to get a task done rather quickly.
[media]
[img]http://i51.tinypic.com/2wdvudz.jpg[/img]
[/media]
5 circle nodes and 1 spinning light node. (Talk about taking programmer art to another level :v:) Obviously you can't see the movement because it's an image, but I really like how it fades in and out. Reminds me of the moon for some reason. : )
My first project I'm going to write using this engine is a 3D music visualizer. It's an easy program and will be fun for me.
[b]Too long didn't read: Learning C#, making a pong like game with online multiplayer. Learning Irrlicht's C++ 3D engine, making a 3D music visualizer.[/b]
[QUOTE=DevBug;28100636]I'm writing a server and I need to keep track of allocations and frees (without an external program like Valgrind). How should I keep track of allocations and frees (I'm using the STL for storage)? I'm going to be doing a lot of allocations and frees and a dump on user request / failure.
1: Remove an entry of an allocation when it's free'd.
2: Add a entry to a free'd list and when a dump is requested update the list.[/QUOTE]
I'm not sure if this is what you want, but this is a simple (but probably quite slow) memory manager I made.
MemoryManager.h
[code]//////////////////////////////////////////////////////
// MemoryManager
//----------------------------------------------------
// #include "MemoryManager.h"
//
// Author: Graeme Pollard
// Date:
// Description:
//////////////////////////////////////////////////////
#pragma once
#include <stdlib.h>
#include <list>
#include "Singleton.h"
//Structure for a memory allocation
struct MemoryAlloc
{
int address;
int size;
char file[255];
char function[255];
int line;
};
class CMemoryManager : public Singleton<CMemoryManager>
{
// Public variables
public:
// Constructors
CMemoryManager(void);
// Destructors
// Methods
void AddMemory(void* ptr, unsigned int size, char *file, int line);
void RemoveMemory(void* ptr);
void PrintUnfreed();
// Private variables
private:
std::list<MemoryAlloc> mAllocations;
int mTotalAllocations;
int mTotalSize;
int mCurrentlyUsed;
int mPeakUsage;
};
#define MemoryManager CMemoryManager::GetSingletonPtr()
//Overrides
#ifdef MEMORY_MANAGER
inline void * __cdecl operator new(unsigned int size, const char *file, int line)
{
void *ptr = (void *)malloc(size);
MemoryManager->AddMemory(ptr, size, (char*)file, line);
return(ptr);
};
inline void __cdecl operator delete(void *p)
{
MemoryManager->RemoveMemory(p);
free(p);
};
inline void __cdecl operator delete[](void *p)
{
MemoryManager->RemoveMemory(p);
free(p);
};
#endif[/code]
MemoryManager.cpp
[code]#include "PCH.hpp"
#include "MemoryManager.h"
#include "Log.h"
#include <stdlib.h>
#include <fstream>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <ctime>
#include <math.h>
//--------------------------------------------------------------------//
// Constructors
//--------------------------------------------------------------------//
CMemoryManager::CMemoryManager()
{
mTotalAllocations = 0;
mTotalSize = 0;
mCurrentlyUsed = 0;
mPeakUsage = 0;
}
//--------------------------------------------------------------------//
//--------------------------------------------------------------------//
// Methods
//--------------------------------------------------------------------//
void CMemoryManager::AddMemory(void* ptr, unsigned int size, char *file, int line)
{
char* function = "global";
MemoryAlloc alloc;
alloc.address = (int)ptr;
alloc.size = size;
strncpy(alloc.file, file, 254);
alloc.line = line;
strncpy(alloc.function, function, 254);
mAllocations.push_back(alloc);
mTotalSize += size;
mCurrentlyUsed += size;
mTotalAllocations++;
if (mCurrentlyUsed > mPeakUsage)
{
mPeakUsage = mCurrentlyUsed;
}
}
//--------------------------------------------------------------------//
void CMemoryManager::RemoveMemory(void* ptr)
{
if (mAllocations.empty())
return;
//Find if there is an entry for this allocation
for (std::list<MemoryAlloc>::iterator it = mAllocations.begin(); it != mAllocations.end(); ++it)
{
if ((int)ptr == it->address)
{
mCurrentlyUsed -= it->size;
mAllocations.erase(it);
break;
}
}
}
//--------------------------------------------------------------------//
void CMemoryManager::PrintUnfreed()
{
//Create log report
/*Log->WriteLine(LOG_TARGET_CLIENT, "");
Log->WriteLine(LOG_TARGET_CLIENT, "-----------------------------------------");
Log->WriteLine(LOG_TARGET_CLIENT, "Unfreed memory allocations");
Log->WriteLine(LOG_TARGET_CLIENT, "-----------------------------------------");
for each(MemoryAlloc alloc in mAllocations)
{
Log->WriteLine(LOG_TARGET_CLIENT,
"0x%X | %i bytes | line %i (%s)", alloc.address, alloc.size, alloc.line, alloc.file);
}
Log->WriteLine(LOG_TARGET_CLIENT, "-----------------------------------------");
Log->WriteLine(LOG_TARGET_CLIENT, "");*/
//Create html report
std::fstream file("MemoryReport.html", std::ios::out);
//Base contents
std::string html = "\
<head>\
<link rel='stylesheet' type='text/css' href='MemoryReport.css' />\
<title>\
Memory Report\
</title>\
</head>\
\
<body>\
<h1>Memory Report</h1>\
<b>Total allocations:</b> %i | <b>Total size:</b> %f kb | <b>Memory lost:</b> %f kb | <b>Peak usage:</b> %i mb<br><br>\
<table><tr><td class='header'>Address<td class='header'>Size<td class='header'>Function<td class='header'>Line<td class='header'>File";
//Add each alloc
char allocFormatted[10000];
for each(MemoryAlloc alloc in mAllocations)
{
sprintf(allocFormatted, "<tr class='content'><td class='content'>0x%X<td class='content'>%i bytes<td class='content'>%s<td class='content'>line %i<td class='content'>%s", alloc.address, alloc.size, alloc.function, alloc.line, alloc.file);
html.append(allocFormatted);
}
html.append("</table></body>");
char htmlFormatted[100000];
sprintf(htmlFormatted, html.c_str(), mTotalAllocations, mTotalSize / 1000.0f, mCurrentlyUsed / 1000.0f, (int)(mPeakUsage / 1000000.0f));
std::string htmlFinal(htmlFormatted);
file.write(htmlFinal.c_str(), htmlFinal.size());
file.close();
}
//--------------------------------------------------------------------//[/code]
MemoryDefines.h
[code]#include "MemoryManager.h"
//Defines
#ifdef MEMORY_MANAGER
#ifndef DEBUG_NEW
#ifdef MEMORY_MANAGEMENT
#define DEBUG_NEW new(__FILE__, __LINE__)
#else
#define DEBUG_NEW new
#endif
#define new DEBUG_NEW
#endif
#endif[/code]
You don't have to have it as a singleton of course. I just do because it's easy. PrintUnfreed() generates a nice little html report of any unfreed memory, including where it was allocated.
Thanks but, I've already rolled my own. Now another question.
Can I do something like this in C++?
[cpp]
template <typename Return, typename Argument>
class Function
{
public:
virtual Return Execute(Argument Arg) = 0;
};
template <typename Class, typename Return, typename Argument>
class TemplateFunction : public Function<Return, Argument>
{
private:
typedef Return (Class::*Function)(Argument);
public:
Return Execute(Argument Arg)
{
....
}
};
[/cpp]
[editline]16th February 2011[/editline]
Holy shit! It compiled!
[QUOTE=Rocket;28097996]Made an outline for my MMO
[url]http://rogers-cybernetics.com/cpancake/mmo.php[/url]
By not sending binary right, I figured out that sphere was reading it as a string.[/QUOTE]
All those numbers next to the fields in the databases - they're not lengths, are they?
You're not storing EVERYTHING as text or char arrays, are you?
[editline]17th February 2011[/editline]
[quote]python will handle the Sqlite and the rest of the server processing.[/quote]
So, you're going to have one sqlite database (Which is flat file) with all of that in it, and you're storing everything as text.
:frog:
I'm trying to embed the V8 JavaScript engine. So far I've built it but, that's where my luck ends. I have encountered an error (which multiple Google searches don't resolve) by trying to compile the [url=http://code.google.com/apis/v8/get_started.html]example[/url], here is the error:
[cpp]
error C2440: 'initializing' : cannot convert from 'v8::Local<T>' to 'v8::String'
with
[
T=v8::String
]
No constructor could take the source type, or constructor overload resolution was ambiguous
[/cpp]
[QUOTE=DevBug;28101978]Can I do something like this in C++?[/QUOTE]
You might be interested in [url=http://www.boost.org/doc/libs/1_45_0/doc/html/function.html]boost::function[/url].
[QUOTE=DevBug;28102856]I'm trying to embed the V8 JavaScript engine. So far I've built it but, that's where my luck ends. I have encountered an error (which multiple Google searches don't resolve) by trying to compile the [url=http://code.google.com/apis/v8/get_started.html]example[/url], here is the error:
[cpp]
error C2440: 'initializing' : cannot convert from 'v8::Local<T>' to 'v8::String'
with
[
T=v8::String
]
No constructor could take the source type, or constructor overload resolution was ambiguous
[/cpp][/QUOTE]
Apparently you can obtain the stored T* via the unary operator *, so to get a T& do **myV8Local.
[editline]17th February 2011[/editline]
[QUOTE=Jawalt;28096995]So I was thinking earlier, about programming languages. What if there was a programming language that was meant to be extended? Like adding entirely new constructs to the language.[/QUOTE]
[url]http://www.pi-programming.org/[/url]
[QUOTE=Jawalt;28096995]So I was thinking earlier, about programming languages. What if there was a programming language that was meant to be extended? Like adding entirely new constructs to the language.[/QUOTE]
That would make for some pretty confusing code methinks. It would be the complete opposite to something like Python which has a strict syntax so that everyone's code looks the same. I mean it's hard enough figuring out someone else's code sometimes.
I have made a implementation of Perlin Noise in C# and this is what happened.
[img]http://dl.dropbox.com/u/2014606/noise.png[/img]
C and C please.
What is going on.
Needs more greyscale.
It is using greyscale, the values are just not translating as such.
Anyway i fixed a bug with the init values and now i have a black and white version of Perlin Noise but with more noise.
[img]http://dl.dropbox.com/u/2014606/noise2.png[/img]
[QUOTE=Overv;28091969]The tokenizer would generate the following table:
[list][*][b]int[/b] - Type name
[*][b]sum[/b] - Identifier
[*][b]=[/b] - Assignment operator
[*][b]a[/b] - Identifier
[*][b]3[/b] - Constant integer
[*][b];[/b] - Expression end[/list][/QUOTE]
The step after tokenizing is parsing the tokens into an Abstract Syntax Tree, like so:
[img]http://cl.ly/4f6A/Screen_shot_2011-02-17_at_7.50.01_PM.png[/img]
Once you have an AST, it's trivial to compile that into any other representation, such as Assembly, some sort of Intermediate Language, or even [url=http://github.com/charliesome/Fructose]PHP[/url]
After that you make developing a language so much easier, though one question what would be the best way to implement a Abstract Syntax Tree.
[QUOTE=Vbits;28104527]After that you make developing a language so much easier, though one question what would be the best way to implement a Abstract Syntax Tree.[/QUOTE]
with a stack
Had a bit of free time in college so I made a random phrase/sentence generator. Uses a collection of 1133 adjectives and 982 nouns to make some phrases.
Some of the best I've seen it output so far are:
[code]aromatic fireman of honorable womens
disturbed authority of funny deaths
annoyed patch of domineering powers
amazing frogs of courageous purposes
innate war of frequent observations
amused nation of extra-small homes
neighborly crime of slippery blows
[/code]
[QUOTE=DevBug;28102856]I'm trying to embed the V8 JavaScript engine. So far I've built it but, that's where my luck ends. I have encountered an error (which multiple Google searches don't resolve) by trying to compile the [url=http://code.google.com/apis/v8/get_started.html]example[/url], here is the error:
[cpp]
error C2440: 'initializing' : cannot convert from 'v8::Local<T>' to 'v8::String'
with
[
T=v8::String
]
No constructor could take the source type, or constructor overload resolution was ambiguous
[/cpp][/QUOTE]
Try
[cpp]*v8::String::Utf8Value(localhere);[/cpp]
for the c-string, or
[cpp]v8::Hande<v8::String>::Cast(localhere);[/cpp]
for a string handle
Does anyone have big mazes with dimensions that are powers of two? Smaller than 8192x8192, I run out of memory for a maze that big.
Just asking to see how well my A* implementation works. The mazes need to be powers of two because I'd rather use binary magic instead of integer division.
I cropped [url=http://img508.imageshack.us/img508/7582/mazem.png]this[/url] from a bigger maze and connected most of the parts manually, which doesn't give very good mazes (there are still unconnected parts along the edges). Took 2953 ms to solve from (0,0) to (2047, 2047), treating regions outside of the map as impassable.
[QUOTE=Kylegar;28096428]other than one creates a struct and the other creates an enum?
I'm assuming that this is C#, and a struct is an ordered data structure, and enums are named constants. While the syntax is the same (myEnums.One), the way things are compiled and used in the language is crazy different.
If you are using an enum, use the enum. if you are creating a struct with some static members, use a struct with static members.[/QUOTE]
In C# structs aren't ordered unless you force them to be with [StructLayout(LayoutKind.Sequential)] attribute. In memory that is.
Does anyone know something silly to work on just to add to a site? I'm having lots and lots of free space and I'm often bored out of my mind.
Some more Mario (I know you've been missing it!!)
Platforms! Working pretty well. Gotta make vertical ones too.
[img_thumb]http://filesmelt.com/dl/platforms.png[/img_thumb]
(They're moving)
Here BAZ, your pageking.
[QUOTE=BAZ;28107824]Please excuse the cornflower blue.
[img]http://i.imgur.com/breL2.png[/img]
This image might not look like much, but I thought it would be cool and probably help speed up development if I added the ability to import a sprite to the game, and then have the physics engine automatically create a body and shape for it.
Here you can see the sprite in the background, and the physics engine creating a close as possible replica out of polygons to use as physics (Which is drawn over the top in this debug mode). The code ignores transparency and just creates physics based on coloured pixels. Worked out well I think!
Someone post a sprite and i'll import it for you![/QUOTE]
Please excuse the cornflower blue.
[img]http://i.imgur.com/breL2.png[/img]
This image might not look like much, but I thought it would be cool and probably help speed up development if I added the ability to import a sprite to the game, and then have the physics engine automatically create a body and shape for it.
Here you can see the sprite in the background, and the physics engine creating a close as possible replica out of polygons to use as physics (Which is drawn over the top in this debug mode). The code ignores transparency and just creates physics based on coloured pixels. Worked out well I think!
Someone post a sprite and i'll import it for you!
Could you outline the algorithm you're using for that?
[url]http://mnbayazit.com/406/bayazit[/url]
[QUOTE=BAZ;28107927][url]http://mnbayazit.com/406/bayazit[/url][/QUOTE]
I like stuff I can understand without being great at programming. 1x thanks.
[QUOTE=Maurice;28107811]Some more Mario (I know you've been missing it!!)
Platforms! Working pretty well. Gotta make vertical ones too.
[img_thumb]http://filesmelt.com/dl/platforms.png[/img_thumb]
(They're moving)[/QUOTE]
Now write a genetic algogorithm that solves it :)
[QUOTE=s0ul0r;28108266]Now write a genetic algogorithm that solves it :)[/QUOTE]
I think you quoted the wrong post?
[QUOTE=Maurice;28108409]I think you quoted the wrong post?[/QUOTE]
Uhm no?..... before rating dumb, think about what I said for a moment -.-
[media]http://www.youtube.com/watch?v=j3__MP1IOfA[/media]
That still seems very unrelated.
Oh hey it's a platformer and it looks like Mario (just like roughly 13,000 other games); make it use a genetic algorithm!
[QUOTE=s0ul0r;28108896]Uhm no?..... before rating dumb, think about what I said for a moment -.-[/QUOTE]
This one is better
[media]http://www.youtube.com/watch?v=0s3d1LfjWCI[/media]
Uses A* path finding and other AI to solve the level and not die
Sorry, you need to Log In to post a reply to this thread.