* License header formatting change

* New IFF chunk formats supported: CST, FBMP, CATS
* Rebranded libfar to simply far
* Started preliminary work on the hitutils package
This commit is contained in:
Fatbag 2012-05-21 23:27:44 -05:00
parent 55659f43b5
commit bc51bb4aad
96 changed files with 2321 additions and 424 deletions

View file

@ -1,5 +1,8 @@
/*
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
Niotso - The New Implementation of The Sims Online
Audio/Audio.hpp
Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,8 @@
/*
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
Niotso - The New Implementation of The Sims Online
Audio/Startup.cpp
Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -24,7 +27,7 @@ IXAudio2MasteringVoice *MasterVoice = NULL;
int Initialize(){
HRESULT result;
result = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE | COINIT_SPEED_OVER_MEMORY);
if(result != S_OK){
MessageBox(Window::hWnd, "Failed to initialize Microsoft COM.", NULL, MB_OK | MB_ICONERROR);
@ -39,7 +42,7 @@ int Initialize(){
Shutdown();
return ERROR_AUDIO_INIT_XAUDIO2;
}
result = pXAudio2->CreateMasteringVoice(&MasterVoice, 2, 44100, 0, 0, NULL);
if(result != S_OK){
MessageBox(Window::hWnd, "Failed to create the mastering voice for XAudio2.", NULL, MB_OK | MB_ICONERROR);
@ -59,7 +62,7 @@ PlayableSound_t * LoadSound(const Sound_t * Sound){
Sound->BitDepth, //wBitsPerSample
0 //cbSize
};
const XAUDIO2_BUFFER buffer = {
0, //Flags
Sound->Duration * wfx.nBlockAlign, //AudioBytes
@ -71,13 +74,13 @@ PlayableSound_t * LoadSound(const Sound_t * Sound){
XAUDIO2_LOOP_INFINITE, //LoopCount
NULL, //pContext
};
IXAudio2SourceVoice* pSourceVoice;
if(FAILED(pXAudio2->CreateSourceVoice(&pSourceVoice, &wfx)))
return NULL;
if(FAILED(pSourceVoice->SubmitSourceBuffer(&buffer)))
return NULL;
PlayableSound_t * PlayableSound = (PlayableSound_t*) malloc(sizeof(PlayableSound_t));
if(!PlayableSound)
return NULL;

View file

@ -1,5 +1,8 @@
/*
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
Niotso - The New Implementation of The Sims Online
Client.cpp
Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -23,7 +26,7 @@ Scene * CurrentScene;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
{
int result;
//Disallow multiple instances of the game from running
CreateMutex(NULL, TRUE, "Global\\TSO_NIOTSO_MUTEX");
if(GetLastError() == ERROR_ALREADY_EXISTS){
@ -40,13 +43,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
Window::Height = 600;
Window::Fullscreen = false;
System::hInst = hInstance;
result = Window::Initialize();
if(result != 0){
Shutdown();
return ERROR_INIT | ERROR_INIT_WINDOW | result;
}
result = System::Initialize();
if(result != 0){
Shutdown();
@ -64,20 +67,20 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
Shutdown();
return ERROR_INIT | ERROR_INIT_AUDIO | result;
}
CurrentScene = new LoginScreen();
if(CurrentScene == NULL || System::SceneFailed){
Shutdown();
return ERROR_INIT | ERROR_INIT_LOGIC | ERROR_LOGIC_CREATE_SCENE;
}
ShowWindow(Window::hWnd, SW_SHOW);
SetForegroundWindow(Window::hWnd);
SetFocus(Window::hWnd);
LARGE_INTEGER PreviousTime;
QueryPerformanceCounter(&PreviousTime);
while(true){
LARGE_INTEGER CurrentTime;
QueryPerformanceCounter(&CurrentTime);
@ -86,9 +89,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
PreviousTime.QuadPart = CurrentTime.QuadPart;
continue;
}
memcpy(&System::UserInput, (const void*) &System::UserInput_v, sizeof(System::UserInput_t));
int result = CurrentScene->RunFor(TimeDelta);
if(result == System::SHUTDOWN)
break;
@ -97,7 +100,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
CurrentScene->Render();
SwapBuffers(Graphics::hDC);
}
PreviousTime.QuadPart = CurrentTime.QuadPart;
QueryPerformanceCounter(&CurrentTime);
float SleepDuration =
@ -107,7 +110,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
ShowWindow(Window::hWnd, SW_HIDE);
delete CurrentScene;
Shutdown();
return 0;
}

View file

@ -1,5 +1,8 @@
/*
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
Niotso - The New Implementation of The Sims Online
EngineInterface.hpp
Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -22,8 +25,9 @@
//Standard libraries
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <memory.h>
#include <windows.h>
#undef NULL
#define NULL 0

View file

@ -1,5 +1,8 @@
/*
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
Niotso - The New Implementation of The Sims Online
Graphics/Font.cpp
Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -25,25 +28,25 @@ FT_Face FontFace;
static void FindStringSize(const wchar_t * String, unsigned * width, unsigned * height, int * xoffset, int * yoffset, int font){
int x = 0, y = 0;
int lowestx = 0, lowesty = 0, highestx = 0, highesty = 0;
for(wchar_t letter=*String; letter!='\0'; letter=*(++String)){
int error = FT_Load_Char(FontFace, letter, FT_LOAD_RENDER);
if(error) continue;
int bottomx = x + FontFace->glyph->bitmap_left;
int bottomy = y + FontFace->glyph->bitmap_top - FontFace->glyph->bitmap.rows;
if(bottomx < lowestx) lowestx = bottomx;
if(bottomy < lowesty) lowesty = bottomy;
int topx = x + FontFace->glyph->bitmap_left + FontFace->glyph->bitmap.width;
int topy = y + FontFace->glyph->bitmap_top;
if(topx > highestx) highestx = topx;
if(topy > highesty) highesty = topy;
x += FontFace->glyph->advance.x >> 6;
y += FontFace->glyph->advance.y >> 6;
}
*width = highestx-lowestx, *height = highesty-lowesty;
*xoffset = -lowestx, *yoffset = -lowesty;
}
@ -53,14 +56,14 @@ void DrawText(Image_t * Image, const wchar_t * String, int x, int y, unsigned wi
//x, y, width, height form the bounding rectangle into which the text should be drawn.
//(x,y) defines the offset to the top-left of the rectangle from the top left of the background.
//The destination image must be stored in bottom-up order.
if(x >= (signed)Image->Width || y >= (signed)Image->Height) return;
//(stringx,stringy) will refer to the top-left of the string in bottom-up coordinates
int stringx, stringy;
unsigned StringWidth, StringHeight;
FindStringSize(String, &StringWidth, &StringHeight, &stringx, &stringy, font);
//Horizontal alignment
if(Alignment < 2) stringx = x; //Left
else if(Alignment < 4) stringx = x+(width-StringWidth+1)/2; //Middle
@ -69,17 +72,17 @@ void DrawText(Image_t * Image, const wchar_t * String, int x, int y, unsigned wi
if(!(Alignment&1)) stringy = y; //Top
else stringy = y+(height-StringHeight+1)/2; //Middle
stringy = Image->Height-stringy-StringHeight;
//Now that we've done the alignment, we can crop the bounding box within the limits of the background image
if(x < 0){ Image->Width += x; x = 0; }
if(y < 0){ Image->Height += y; y = 0; }
if(width > Image->Width) width = Image->Width;
if(height > Image->Height) height = Image->Height;
for(wchar_t letter=*String; letter!='\0'; letter=*(++String)){
int error = FT_Load_Char(FontFace, letter, FT_LOAD_RENDER);
if(error) continue;
int cWidth = FontFace->glyph->bitmap.width, cHeight = FontFace->glyph->bitmap.rows;
if(cWidth && cHeight){
uint8_t * cRender; /* Convert to Bottom-up */
@ -108,7 +111,7 @@ void DrawText(Image_t * Image, const wchar_t * String, int x, int y, unsigned wi
}
stringx -= FontFace->glyph->bitmap_left;
stringy -= FontFace->glyph->bitmap_top-cHeight;
if(FontFace->glyph->bitmap.pitch > 0) free(cRender);
}
stringx += FontFace->glyph->advance.x >> 6;
@ -123,7 +126,7 @@ Image_t * StringImage(const wchar_t * String, int font, COLORREF Color){
unsigned StringWidth, StringHeight;
int stringx, stringy;
FindStringSize(String, &StringWidth, &StringHeight, &stringx, &stringy, font);
Image->Data = (uint8_t*) malloc(4 * StringWidth * StringHeight);
if(Image->Data == NULL){
free(Image);
@ -135,11 +138,11 @@ Image_t * StringImage(const wchar_t * String, int font, COLORREF Color){
Image->Data[i++] = GetRValue(Color);
Image->Data[i++] = 0;
}
for(wchar_t letter=*String; letter!='\0'; letter=*(++String)){
int error = FT_Load_Char(FontFace, letter, FT_LOAD_RENDER);
if(error) continue;
int cWidth = FontFace->glyph->bitmap.width, cHeight = FontFace->glyph->bitmap.rows;
if(cWidth && cHeight){
uint8_t * cRender; /* Convert to Bottom-up */
@ -160,13 +163,13 @@ Image_t * StringImage(const wchar_t * String, int font, COLORREF Color){
}
stringx -= FontFace->glyph->bitmap_left;
stringy -= FontFace->glyph->bitmap_top-cHeight;
if(FontFace->glyph->bitmap.pitch > 0) free(cRender);
}
stringx += FontFace->glyph->advance.x >> 6;
stringy += FontFace->glyph->advance.y >> 6;
}
Image->Width = StringWidth;
Image->Height = StringHeight;
Image->Format = FIMG_BGRA32;

View file

@ -1,5 +1,8 @@
/*
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
Niotso - The New Implementation of The Sims Online
Graphics/Graphics.hpp
Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -24,10 +27,10 @@ namespace Graphics {
void Shutdown();
extern HDC hDC;
extern HGLRC hRC;
int InitGL();
void ResizeViewport(unsigned width, unsigned height);
enum TextAlignment {
ALIGN_LEFT_TOP,
ALIGN_LEFT_CENTER,
@ -36,7 +39,7 @@ namespace Graphics {
ALIGN_RIGHT_TOP,
ALIGN_RIGHT_CENTER
};
//Font.cpp
extern FT_Library FreeTypeLibrary;
extern FT_Face FontFace;

View file

@ -1,5 +1,8 @@
/*
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
Niotso - The New Implementation of The Sims Online
Graphics/Startup.cpp
Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -29,7 +32,7 @@ int Initialize(){
Shutdown();
return ERROR_GRAPHICS_OBTAIN_DC;
}
const PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), 1, //Size and version
PFD_DRAW_TO_WINDOW | //dwFlags
@ -46,7 +49,7 @@ int Initialize(){
0, //Reserved
0, 0, 0 //Masks
};
unsigned PixelFormat = ChoosePixelFormat(hDC, &pfd);
if(!PixelFormat){
MessageBox(Window::hWnd, "Failed to find a suitable pixel format for the device context.", NULL, MB_OK | MB_ICONERROR);
@ -59,31 +62,31 @@ int Initialize(){
Shutdown();
return ERROR_GRAPHICS_SET_PIXELFORMAT;
}
hRC = wglCreateContext(hDC);
if(!hRC){
MessageBox(Window::hWnd, "Failed to create an OpenGL rendering context.", NULL, MB_OK | MB_ICONERROR);
Shutdown();
return ERROR_GRAPHICS_CREATE_GLRC;
}
if(!wglMakeCurrent(hDC, hRC)){
MessageBox(Window::hWnd, "Failed to activate the OpenGL device context.", NULL, MB_OK | MB_ICONERROR);
Shutdown();
return ERROR_GRAPHICS_ACTIVATE_GLRC;
}
BOOL (WINAPI *wglSwapIntervalEXT)(int) = (BOOL (WINAPI *)(int)) wglGetProcAddress("wglSwapIntervalEXT");
if(wglSwapIntervalEXT) wglSwapIntervalEXT(1);
int (WINAPI *wglGetSwapIntervalEXT)(void) = (int (WINAPI *)(void)) wglGetProcAddress("wglGetSwapIntervalEXT");
if(wglGetSwapIntervalEXT) wglGetSwapIntervalEXT(); //Seems necessary on some cards
int result = InitGL();
if(result != 0){
Shutdown();
return ERROR_GRAPHICS_INIT_GLSCENE | result;
}
ResizeViewport(Window::Width, Window::Height);
return 0;
}

View file

@ -1,5 +1,8 @@
/*
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
Niotso - The New Implementation of The Sims Online
Graphics/Viewport.cpp
Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,8 @@
/*
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
Niotso - The New Implementation of The Sims Online
Scene/LoginScreen/LoginScreen.cpp
Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -43,9 +46,9 @@ LoginScreen::LoginScreen() : Scene(0){
glMatrixMode(GL_TEXTURE);
glGenTextures(TEX_COUNT, texture);
FT_Set_Char_Size(Graphics::FontFace, 0, 22*64, 0, 0);
for(int i=TEX_EAGAMES; i<=TEX_SETUP; i++){
Image_t * Image = File::ReadImageFile(images[i]);
if(!Image){
@ -74,12 +77,12 @@ LoginScreen::LoginScreen() : Scene(0){
MessageBox(Window::hWnd, Buffer, NULL, MB_OK | MB_ICONERROR);
EXIT_SCENE();
}
if(i == TEX_MAXIS){
Graphics::DrawText(Image, L"Maxis\x2122 is an Electronic Arts\x2122 brand.", 0, 600-146, 800, 146,
Graphics::ALIGN_CENTER_CENTER, 0, RGB(0xef, 0xe3, 0x8c));
}
glBindTexture(GL_TEXTURE_2D, texture[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@ -89,7 +92,7 @@ LoginScreen::LoginScreen() : Scene(0){
free(Image->Data);
free(Image);
}
image[IMG_COPYRIGHT] = Graphics::StringImage(L"(c) 2002, 2003 Electronic Arts Inc. All rights reserved.",
0, RGB(0xef, 0xe3, 0x8c));
if(image[IMG_COPYRIGHT] == NULL){
@ -118,7 +121,7 @@ LoginScreen::LoginScreen() : Scene(0){
GL_UNSIGNED_BYTE, image[IMG_STATUS+i]->Data);
free(image[IMG_STATUS+i]->Data);
}
for(int i=0; i<SND_COUNT; i++){
Sound_t * Sound = File::ReadSoundFile(sounds[i]);
if(!Sound){
@ -147,7 +150,7 @@ LoginScreen::LoginScreen() : Scene(0){
MessageBox(Window::hWnd, Buffer, NULL, MB_OK | MB_ICONERROR);
EXIT_SCENE();
}
sound[i] = Audio::LoadSound(Sound);
free(Sound);
if(!sound){
@ -157,11 +160,11 @@ LoginScreen::LoginScreen() : Scene(0){
Audio::PlaySound(sound[i]);
}
}
LoginScreen::~LoginScreen(){
for(int i=0; i<IMG_COUNT; i++){ if(image[i]) free(image[i]); }
glDeleteTextures(TEX_COUNT, texture);
for(int i=0; i<SND_COUNT; i++){
if(sound[i]){
Audio::DeleteSound(sound[i]);

View file

@ -1,5 +1,8 @@
/*
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
Niotso - The New Implementation of The Sims Online
Scene/LoginScreen/LoginScreen.hpp
Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -47,7 +50,7 @@ class LoginScreen : public Scene {
LoginScreen();
~LoginScreen();
void Render();
private:
int Run(float TimeDelta);
};

View file

@ -1,5 +1,8 @@
/*
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
Niotso - The New Implementation of The Sims Online
Scene/Scene.hpp
Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -34,7 +37,7 @@ class Scene {
if(TickPeriod == 0){
return Run(TimeDelta);
}
bool Redraw = false;
RealTimeDelta += TimeDelta;
while(RealTimeDelta >= 0){
@ -46,7 +49,7 @@ class Scene {
}
return (Redraw) ? 1 : -1;
}
virtual void Render() = 0;
virtual ~Scene() {};
};

View file

@ -1,5 +1,8 @@
/*
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
Niotso - The New Implementation of The Sims Online
System/System.cpp
Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -24,17 +27,17 @@ HANDLE Process;
HANDLE ProcessHeap;
LARGE_INTEGER ClockFreq;
volatile float FramePeriod;
UserInput_t UserInput = {0};
UserInput_t UserInput = UserInput_t();
volatile UserInput_t UserInput_v;
bool SceneFailed = false;
int Initialize(){
QueryPerformanceFrequency(&ClockFreq);
DEVMODE dm;
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
System::FramePeriod = 1.0f/dm.dmDisplayFrequency;
if(FT_Init_FreeType(&Graphics::FreeTypeLibrary)){
MessageBox(Window::hWnd, "Failed to initialize FreeType.", NULL, MB_OK | MB_ICONERROR);
Graphics::FreeTypeLibrary = NULL;

View file

@ -1,5 +1,8 @@
/*
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
Niotso - The New Implementation of The Sims Online
System/System.hpp
Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -24,7 +27,7 @@ namespace System {
extern HANDLE ProcessHeap;
extern LARGE_INTEGER ClockFreq;
extern volatile float FramePeriod;
struct UserInput_t {
bool Keys[256];
bool MouseDown;
@ -34,7 +37,7 @@ namespace System {
extern volatile UserInput_t UserInput_v;
extern bool SceneFailed;
//Constants
enum {
SHUTDOWN = 0

View file

@ -12,7 +12,7 @@ Development Phase: Planning
Technical Preview 1
Schedule: (Not very subject to change)
1. Implement cst and uis parsers [40%]
2. Replicate functionality up until the login dialog [0%]
2. Replicate functionality up until the login dialog [90%]
3. Implement the OpenGL-based windowing system
4. Replicate character selection and creation features and the city selection dialog
5. Implement the code needed to allow the game to read all necessary files from the TSOClient folder

View file

@ -1,5 +1,8 @@
/*
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
Niotso - The New Implementation of The Sims Online
Window/Window.cpp
Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View file

@ -1,5 +1,8 @@
/*
Niotso - Copyright (C) 2012 Fatbag <X-Fi6@phppoll.org>
Niotso - The New Implementation of The Sims Online
Window/Window.hpp
Copyright (c) 2012 Niotso Project <http://niotso.org/>
Author(s): Fatbag <X-Fi6@phppoll.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by