commit:537d99f7362abc5b8e07ca8ad2567f4c1b98bb2c
author:Chip Black
committer:Chip Black
date:Thu May 19 01:17:31 2011 -0500
parents:
Initial commit: basic port of SwarmDS.
diff --git a/buildit.cmd b/buildit.cmd
line changes: +42/-0
index 0000000..d88cc18
--- /dev/null
+++ b/buildit.cmd
@@ -0,0 +1,42 @@
+@echo off
+@rem Set the device you want to build for to 1
+@rem Use Pixi to allow running on either device
+set PRE=0
+set PIXI=1
+set DEBUG=1
+
+@rem List your source files here
+set SRC=src\swarm.cpp src\Pixel.cpp
+
+@rem List the libraries needed
+set LIBS=-lSDL -lpdl -lGLES_CM
+
+@rem Name your output executable
+set OUTFILE=swarm
+
+if %PRE% equ 0 if %PIXI% equ 0 goto :END
+
+if %DEBUG% equ 1 (
+   set DEVICEOPTS=-g
+) else (
+   set DEVICEOPTS=
+)
+
+if %PRE% equ 1 (
+   set DEVICEOPTS=%DEVICEOPTS% -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp
+)
+
+if %PIXI% equ 1 (
+   set DEVICEOPTS=%DEVICEOPTS% -mcpu=arm1136jf-s -mfpu=vfp -mfloat-abi=softfp
+)
+
+echo %DEVICEOPTS%
+
+arm-none-linux-gnueabi-gcc %DEVICEOPTS% -o %OUTFILE% %SRC% "-I%PALMPDK%\include" "-I%PALMPDK%\include\SDL" "-L%PALMPDK%\device\lib" -Wl,--allow-shlib-undefined %LIBS%
+
+goto :EOF
+
+:END
+echo Please select the target device by editing the PRE/PIXI variable in this file.
+exit /b 1
+

diff --git a/package/appinfo.json b/package/appinfo.json
line changes: +10/-0
index 0000000..60aad84
--- /dev/null
+++ b/package/appinfo.json
@@ -0,0 +1,10 @@
+{
+	"id": "com.dominionofawesome.swarm",
+	"version": "0.9.0",
+	"vendor": "The Dominion of Awesome",
+	"type": "pdk",
+	"main": "swarm",
+	"title": "Swarm",
+	"icon": "icon.png",
+	"requiredMemory": 10
+}

diff --git a/package/framework_config.json b/package/framework_config.json
line changes: +7/-0
index 0000000..40d4e8d
--- /dev/null
+++ b/package/framework_config.json
@@ -0,0 +1,7 @@
+{
+	"logLevel": 99,
+	"debuggingEnabled": true,
+	"timingEnabled": false,
+	"logEvents": false,
+	"escapeHTMLInTemplates" : true
+}

diff --git a/package/package.properties b/package/package.properties
line changes: +1/-0
index 0000000..ea83be1
--- /dev/null
+++ b/package/package.properties
@@ -0,0 +1 @@
+filemode.755 = swarm

diff --git a/packageit.cmd b/packageit.cmd
line changes: +7/-0
index 0000000..8d9967d
--- /dev/null
+++ b/packageit.cmd
@@ -0,0 +1,7 @@
+@echo off
+call buildit.cmd
+
+copy swarm package\
+arm-none-linux-gnueabi-strip package\swarm
+
+palm-package package

diff --git a/src/Pixel.cpp b/src/Pixel.cpp
line changes: +45/-0
index 0000000..5a27aee
--- /dev/null
+++ b/src/Pixel.cpp
@@ -0,0 +1,45 @@
+#include "Pixel.h"
+//#include <stdlib.h>
+#include <GLES/gl.h>
+#include "SDL.h"
+
+Pixel::Pixel(void) {
+	this->x = (rand() / (float)RAND_MAX) * 320.0;
+	this->y = (rand() / (float)RAND_MAX) * 400.0;
+	this->vx = (rand() / (float)RAND_MAX) * 10.0 - 5.0;
+	this->vy = (rand() / (float)RAND_MAX) * 10.0 - 5.0;
+	this->lastupdate = SDL_GetTicks();
+}
+
+Pixel::~Pixel(void) {
+}
+
+void Pixel::accel(float x, float y) {
+	this->vx += x;
+	if (this->vx > 100.0)
+		this->vx = 100.0;
+	else if (this->vx < -100.0)
+		this->vx = -100.0;
+	this->vy += y;
+	if (this->vy > 100.0)
+		this->vy = 100.0;
+	else if (this->vy < -100.0)
+		this->vy = -100.0;
+}
+
+void Pixel::update() {
+	Uint32 now = SDL_GetTicks();
+	float dt = (now - this->lastupdate) / 75.0;
+	if (dt < 1000) {   // If we're running less than 1FPS, don't bother updating.
+		this->x += this->vx * dt;
+		this->y += this->vy * dt;
+	}
+	this->lastupdate = now;
+}
+
+void Pixel::draw(GLfloat *vertices) {
+	vertices[0] = this->x;
+	vertices[1] = this->y;
+	vertices[3] = this->x - this->vx / 4.0f;
+	vertices[4] = this->y - this->vy / 4.0f;
+} 
\ No newline at end of file

diff --git a/src/Pixel.h b/src/Pixel.h
line changes: +18/-0
index 0000000..932b009
--- /dev/null
+++ b/src/Pixel.h
@@ -0,0 +1,18 @@
+#pragma once
+#include <GLES/gl.h>
+#include "SDL.h"
+
+class Pixel
+{
+private:
+	Uint32 lastupdate;
+public:
+	float x, y;
+	float vx, vy;
+
+	Pixel(void);
+	~Pixel(void);
+	void accel(float x, float y);
+	void update();
+	void draw(GLfloat *);
+};

diff --git a/src/swarm.cpp b/src/swarm.cpp
line changes: +196/-0
index 0000000..78d5133
--- /dev/null
+++ b/src/swarm.cpp
@@ -0,0 +1,196 @@
+#include <stdio.h>
+#include <math.h>
+
+#include <GLES/gl.h>
+#include "SDL.h"
+#include "PDL.h"
+#include "Pixel.h"
+#define NPIXELS 2000
+
+SDL_Surface* screen;               // Screen surface
+Uint16 mx, my;
+Pixel** pixels;
+GLfloat* vertices;
+
+#ifdef WIN32
+extern "C" 
+#endif
+GL_API int GL_APIENTRY _dgles_load_library(void *, void *(*)(void *, const char *));
+
+static void *proc_loader(void *h, const char *name)
+{
+    (void) h;
+    return SDL_GL_GetProcAddress(name);
+}
+
+void init() {
+	// Set up OpenGL
+	glClearColor(0.5f, 0.5f, 0.5f, 0.0f);
+	glMatrixMode(GL_PROJECTION);
+	glLoadIdentity();
+	glOrthof(0.0f, 320.0f, 400.0f, 0.0f, -1.0f, 1.0f);
+	glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
+
+	// Initialize vertices
+	vertices = new GLfloat[NPIXELS * 6];
+	memset(vertices, 0, sizeof(GLfloat) * NPIXELS * 6);
+	glEnableClientState(GL_VERTEX_ARRAY);
+	glVertexPointer(3, GL_FLOAT, 0, vertices);
+
+	// Center cursor
+	mx = 160;
+	my = 200;
+
+	// Initialize pixel objects
+	pixels = new Pixel*[NPIXELS];
+	for (int x = 0; x < NPIXELS; x++) {
+		pixels[x] = new Pixel();
+	}
+
+}
+
+void pushPixels(int pushX, int pushY) {
+	// Apply force to each pixel outwards from the mouse
+	for (int i = 0; i < NPIXELS; i++) {
+		// Get the direction
+		float dx = pixels[i]->x - pushX;
+		float dy = pixels[i]->y - pushY;
+		float mag = sqrtf(dx*dx + dy*dy);
+		dx /= mag;
+		dy /= mag;
+
+		// Apply force.
+		pixels[i]->accel(dx * 10.0, dy * 10.0);
+	}
+}
+
+void engine() {
+	// Clear the canvas
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	// Update cursor
+	vertices[0] = mx - 5;
+	vertices[1] = my - 5;
+	vertices[3] = mx + 5;
+	vertices[4] = my - 5;
+	vertices[6] = mx + 5;
+	vertices[7] = my + 5;
+	vertices[9] = mx - 5;
+	vertices[10] = my + 5;
+	glDrawArrays(GL_LINE_LOOP, 0, 4);
+
+	// Update all pixel objects
+	for (int i = 0; i < NPIXELS; i++) {
+		// Get distance
+		float dx = mx - pixels[i]->x;
+		float dy = my - pixels[i]->y;
+		float d = sqrtf(dx*dx + dy*dy);
+
+		// Apply acceleration to pixels towards the mouse cursor
+		float ax = dx / 50.0;
+		float ay = dy / 50.0;
+
+		// Apply a drag proportional to the distance from the cursor
+		if (d > 25.0) {
+			ax += -pixels[i]->vx * (d - 25.0) / 1000.0;
+			ay += -pixels[i]->vy * (d - 25.0) / 1000.0;
+		}
+
+		// And a "chaotic" acceleration inversely proportional
+		// to the distance from the cursor
+		ax += ((rand() / (float)RAND_MAX) * 40.0 - 20.0) / d;
+		ay += ((rand() / (float)RAND_MAX) * 40.0 - 20.0) / d;
+
+		pixels[i]->accel(ax,ay);
+		pixels[i]->update();
+		pixels[i]->draw(&vertices[i*6]);
+	}
+	glDrawArrays(GL_LINES, 0, NPIXELS * 2);
+}
+
+int main(int argc, char** argv)
+{
+    // Initialize the SDL library with the Video subsystem
+    SDL_Init(SDL_INIT_VIDEO);
+
+    // start the PDL library
+    PDL_Init(0);
+    
+    // Tell it to use OpenGL ES version 1.1
+    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
+
+    // Set the video mode to full screen with OpenGL-ES support
+    screen = SDL_SetVideoMode(320, 400, 0, SDL_OPENGL);
+    if (!screen) {
+		printf("Could not initialize video!\n");
+		exit(1);
+    }
+    printf("width: %d, height, %d\n", screen->w, screen->h);
+
+#if WIN32
+    // Load the desktop OpenGL-ES emulation library
+    _dgles_load_library(NULL, proc_loader);
+#endif
+
+	init();
+
+    // Event descriptor
+    SDL_Event Event;
+	int app_is_active = 1;
+	Uint32 last = SDL_GetTicks();
+	int fps_counter = 0;
+
+    do {
+        // Process the events
+		if (!app_is_active)
+			SDL_WaitEvent(NULL);
+        while (SDL_PollEvent(&Event)) {
+            switch (Event.type) {
+                // List of keys that have been pressed
+                case SDL_KEYDOWN:
+                    switch (Event.key.keysym.sym) {
+                        // Escape forces us to quit the app
+                        // this is also sent when the user makes a back gesture
+                        case SDLK_ESCAPE:
+                            Event.type = SDL_QUIT;
+                            break;
+                        default:
+                            break;
+                    }
+                    break;
+				case SDL_MOUSEMOTION:
+					mx = Event.motion.x;
+					my = Event.motion.y;
+					break;
+				case SDL_MOUSEBUTTONDOWN:
+					pushPixels(Event.button.x, Event.button.y);
+				case SDL_ACTIVEEVENT:
+					if (Event.active.state == SDL_APPACTIVE)
+						app_is_active = Event.active.gain;
+					break;
+                default:
+                    break;
+            }
+        }
+
+		engine();
+		glFlush();
+		SDL_GL_SwapBuffers();
+
+		// Calculate FPS
+		fps_counter++;
+		Uint32 now = SDL_GetTicks();
+		if (now - last > 1000) {
+			printf("%d FPS\n", fps_counter);
+			fps_counter = 0;
+			last = now;
+		}
+    } while (Event.type != SDL_QUIT);
+    // We exit anytime we get a request to quit the app
+
+    // Cleanup
+    PDL_Quit();
+    SDL_Quit();
+
+    return 0;
+}

diff --git a/swarm.sln b/swarm.sln
line changes: +20/-0
index 0000000..28af9aa
--- /dev/null
+++ b/swarm.sln
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "swarm", "swarm.vcproj", "{084AA5FB-DC4E-4A84-B198-19448669AD25}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Win32 = Debug|Win32
+		Release|Win32 = Release|Win32
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{084AA5FB-DC4E-4A84-B198-19448669AD25}.Debug|Win32.ActiveCfg = Debug|Win32
+		{084AA5FB-DC4E-4A84-B198-19448669AD25}.Debug|Win32.Build.0 = Debug|Win32
+		{084AA5FB-DC4E-4A84-B198-19448669AD25}.Release|Win32.ActiveCfg = Release|Win32
+		{084AA5FB-DC4E-4A84-B198-19448669AD25}.Release|Win32.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

diff --git a/swarm.vcproj b/swarm.vcproj
line changes: +210/-0
index 0000000..d9502e0
--- /dev/null
+++ b/swarm.vcproj
@@ -0,0 +1,210 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="9.00"
+	Name="swarm"
+	ProjectGUID="{084AA5FB-DC4E-4A84-B198-19448669AD25}"
+	RootNamespace="swarm"
+	Keyword="Win32Proj"
+	TargetFrameworkVersion="131072"
+	>
+	<Platforms>
+		<Platform
+			Name="Win32"
+		/>
+	</Platforms>
+	<ToolFiles>
+	</ToolFiles>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="&quot;$(PalmPDK)\include&quot;;&quot;$(PalmPDK)\include\SDL&quot;"
+				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
+				MinimalRebuild="true"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="4"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="SDLmain.lib SDL.lib dgles.lib libpdl.lib ws2_32.lib"
+				LinkIncremental="2"
+				AdditionalLibraryDirectories="$(PalmPDK)\host\lib"
+				GenerateDebugInformation="true"
+				SubSystem="2"
+				RandomizedBaseAddress="1"
+				DataExecutionPrevention="0"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)"
+			ConfigurationType="1"
+			CharacterSet="1"
+			WholeProgramOptimization="1"
+			>
+			<Tool
+				Name="VCPreBuildEventTool"
+			/>
+			<Tool
+				Name="VCCustomBuildTool"
+			/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"
+			/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"
+			/>
+			<Tool
+				Name="VCMIDLTool"
+			/>
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalIncludeDirectories="&quot;$(PalmPDK)\include&quot;;&quot;$(PalmPDK)\include\SDL&quot;"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
+				RuntimeLibrary="2"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="true"
+				DebugInformationFormat="3"
+			/>
+			<Tool
+				Name="VCManagedResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCResourceCompilerTool"
+			/>
+			<Tool
+				Name="VCPreLinkEventTool"
+			/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="SDLmain.lib SDL.lib dglesv2.lib libpdl.lib"
+				LinkIncremental="1"
+				AdditionalLibraryDirectories="$(PalmPDK)\host\lib"
+				GenerateDebugInformation="true"
+				SubSystem="2"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				RandomizedBaseAddress="1"
+				DataExecutionPrevention="0"
+				TargetMachine="1"
+			/>
+			<Tool
+				Name="VCALinkTool"
+			/>
+			<Tool
+				Name="VCManifestTool"
+			/>
+			<Tool
+				Name="VCXDCMakeTool"
+			/>
+			<Tool
+				Name="VCBscMakeTool"
+			/>
+			<Tool
+				Name="VCFxCopTool"
+			/>
+			<Tool
+				Name="VCAppVerifierTool"
+			/>
+			<Tool
+				Name="VCPostBuildEventTool"
+			/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+			>
+			<File
+				RelativePath="..\src\Pixel.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\src\swarm.cpp"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+			>
+			<File
+				RelativePath="..\src\Pixel.h"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+			UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+			>
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>